Skip to content

Commit

Permalink
save ROM file
Browse files Browse the repository at this point in the history
  • Loading branch information
Entroper committed Nov 16, 2016
1 parent c23dcac commit 5dba8c2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 34 deletions.
12 changes: 12 additions & 0 deletions FF1Randomizer/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="FF1Randomizer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<userSettings>
<FF1Randomizer.Properties.Settings>
<setting name="RomFilename" serializeAs="String">
<value />
</setting>
</FF1Randomizer.Properties.Settings>
</userSettings>
</configuration>
48 changes: 38 additions & 10 deletions FF1Randomizer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MainWindow : Window
private string _filename;
private Blob _seed;

public const string Version = "0.8.1";
public const string Version = "0.8.2";

private class MainWindowViewModel
{
Expand All @@ -39,6 +39,7 @@ public MainWindow()

DataContext = new MainWindowViewModel();

TryOpenSavedFilename();
GenerateSeed();

SetScaleFactorLabel(PriceScaleFactorSlider, PriceScaleFactorLabel);
Expand All @@ -47,6 +48,24 @@ public MainWindow()
SetFlagsText(null, null);
}

private void TryOpenSavedFilename()
{
if (String.IsNullOrEmpty(Properties.Settings.Default.RomFilename))
{
return;
}

if (!File.Exists(Properties.Settings.Default.RomFilename))
{
Properties.Settings.Default.RomFilename = null;
Properties.Settings.Default.Save();

return;
}

ValidateRom(Properties.Settings.Default.RomFilename);
}

private void GenerateSeed()
{
_seed = Blob.Random(4);
Expand All @@ -64,18 +83,27 @@ private void RomButton_Click(object sender, RoutedEventArgs e)
var result = openFileDialog.ShowDialog(this);
if (result == true)
{
var randomizer = new FF1Rom(openFileDialog.FileName);
if (!randomizer.Validate())
{
MessageBox.Show("ROM does not appear to be valid. Proceed at your own risk.", "Validation Error");
}

_filename = openFileDialog.FileName;
RomTextBox.Text = openFileDialog.SafeFileName;
GenerateButton.IsEnabled = true;
ValidateRom(openFileDialog.FileName);

Properties.Settings.Default.RomFilename = _filename;
Properties.Settings.Default.Save();
}
}

private void ValidateRom(string filename)
{
var rom = new FF1Rom(filename);
if (!rom.Validate())
{
MessageBox.Show("ROM does not appear to be valid. Proceed at your own risk.", "Validation Error");
}

_filename = filename;
var slashIndex = filename.LastIndexOfAny(new[] { '/', '\\' });
RomTextBox.Text = filename.Substring(slashIndex + 1);
GenerateButton.IsEnabled = true;
}

private void SeedButton_Click(object sender, RoutedEventArgs e)
{
GenerateSeed();
Expand Down
46 changes: 27 additions & 19 deletions FF1Randomizer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions FF1Randomizer/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="FF1Randomizer.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="RomFilename" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 5dba8c2

Please sign in to comment.