Skip to content

Commit

Permalink
Checking for program version too when checking for updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
PunishedPineapple committed Apr 27, 2020
1 parent 9f12684 commit 64e9da0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 39 deletions.
60 changes: 37 additions & 23 deletions Data/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Xml;
using System.Net;
using System.Windows.Forms;
using System.Diagnostics;

namespace WaymarkLibrarian
{
Expand Down Expand Up @@ -61,48 +62,61 @@ protected void CheckForUpdates()
// Read the config if we have it.
if( File.Exists( currentVersionsFilePath ) )
{
string programVer = "";
string gameDataCfgVer = "";
string zoneDictionaryDatVer = "";
List<string> lines = File.ReadLines( currentVersionsFilePath ).ToList();
foreach( string line in lines )
{
if( line.Split( '=' ).First().Trim().Equals( "Program" ) ) programVer = line.Split( '=' ).Last().Trim();
if( line.Split( '=' ).First().Trim().Equals( "GameData.cfg" ) ) gameDataCfgVer = line.Split( '=' ).Last().Trim();
if( line.Split( '=' ).First().Trim().Equals( "ZoneDictionary.dat" ) ) zoneDictionaryDatVer = line.Split( '=' ).Last().Trim();
}

// Update game data config.
if( gameDataCfgVer.Length > 0 &&
gameDataCfgVer != GameDataSettings.GameVersion &&
MessageBox.Show( "A new version of the game data configuration file was found. Update now?", "Update?", MessageBoxButtons.YesNo ) == DialogResult.Yes )
// Notify the user if a new version of the program is available.
if( programVer.Length > 0 &&
programVer != FileVersionInfo.GetVersionInfo( System.Reflection.Assembly.GetExecutingAssembly().Location ).FileVersion )
{
try
{
webClient.DownloadFile( "https://punishedpineapple.github.io/WaymarkLibrarian/Support/GameData.cfg", updateFolderPath + "\\GameData.cfg" );
File.Copy( updateFolderPath + "\\GameData.cfg", GameDataSettings.ConfigFilePath, true );
}
catch
{
MessageBox.Show( "Update failed!", "Failure!" );
}
MessageBox.Show( "A new version of this program is available. Go to https://github.com/PunishedPineapple/WaymarkLibrarian/releases to download the latest version.", "New Version" );
}

// Update zone dictionary.
if( zoneDictionaryDatVer.Length > 0 &&
zoneDictionaryDatVer != ZoneInfoSettings.GameVersion &&
MessageBox.Show( "A new version of the zone dictionary file was found. Update now?", "Update?", MessageBoxButtons.YesNo ) == DialogResult.Yes )
// Only check for configuration updates if the program is up to date (since file formats could conceivably change).
else
{
try
// Update game data config.
if( gameDataCfgVer.Length > 0 &&
gameDataCfgVer != GameDataSettings.GameVersion &&
MessageBox.Show( "A new version of the game data configuration file was found. Update now?", "Update?", MessageBoxButtons.YesNo ) == DialogResult.Yes )
{
webClient.DownloadFile( "https://punishedpineapple.github.io/WaymarkLibrarian/Support/ZoneDictionary.dat", updateFolderPath + "\\ZoneDictionary.dat" );
File.Copy( updateFolderPath + "\\ZoneDictionary.dat", ZoneInfoSettings.ConfigFilePath, true );
try
{
webClient.DownloadFile( "https://punishedpineapple.github.io/WaymarkLibrarian/Support/GameData.cfg", updateFolderPath + "\\GameData.cfg" );
File.Copy( updateFolderPath + "\\GameData.cfg", GameDataSettings.ConfigFilePath, true );
}
catch
{
MessageBox.Show( "Update failed!", "Failure!" );
}
}
catch

// Update zone dictionary.
if( zoneDictionaryDatVer.Length > 0 &&
zoneDictionaryDatVer != ZoneInfoSettings.GameVersion &&
MessageBox.Show( "A new version of the zone dictionary file was found. Update now?", "Update?", MessageBoxButtons.YesNo ) == DialogResult.Yes )
{
MessageBox.Show( "Update failed!", "Failure!" );
try
{
webClient.DownloadFile( "https://punishedpineapple.github.io/WaymarkLibrarian/Support/ZoneDictionary.dat", updateFolderPath + "\\ZoneDictionary.dat" );
File.Copy( updateFolderPath + "\\ZoneDictionary.dat", ZoneInfoSettings.ConfigFilePath, true );
}
catch
{
MessageBox.Show( "Update failed!", "Failure!" );
}
}
}
}

// Clean up the update files.
Directory.Delete( updateFolderPath, true );
}

Expand Down
2 changes: 1 addition & 1 deletion Data/GameDataConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Reload()

protected void SetDefaultConfig()
{
GameVersion = "2020.02.26.0000.0001";
GameVersion = "2020.03.27.0000.0000";
WaymarkDataFileName = "UISAVE.DAT";
ExpectedFileLength_Bytes = 0x7420;
WaymarkDataOffset = 0x6C97;
Expand Down
8 changes: 4 additions & 4 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[assembly: AssemblyTitle("WaymarkLibrarian")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("PunishedPineapple")]
[assembly: AssemblyProduct("WaymarkLibrarian")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © PunishedPineapple 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.9.0.0")]
[assembly: AssemblyFileVersion("0.9.0.0")]
6 changes: 4 additions & 2 deletions ToDo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
High Priority:

- Why are character directory last modified times being updated, but then only sometimes? May be related to copying a backup of the UISAVE?
- Try to see if the UISAVE.DAT header contains a file format version that can be used instead of hoping that file length is good enough.
- Dictionary is a most likely poor choice for the underlying data structure in the zone dictionary since we want to be able to access by index as well. Probably keep two lists and manage them ourselves.
- Try to see if the UISAVE.DAT header contains a file format version that can be used instead of hoping that file length is a good enough discriminator.
- Dictionary is a most likely poor choice for the underlying data structure in the zone dictionary since we want to be able to access by index as well. Maybe keep two lists and manage them ourselves?


Low Priority / Cleanup:

- It feels super janky having web stuff and especially popup dialogs in the config classes. See about making that stuff less of a mess.
- Config classes are kind of a mess overall.
- Clean up code formatting as much as reasonably possible.
- Keep looking for ways to get character name from configuration data.
- See if there is a good way to get duty names from zone names so that the zone dictionary looks a bit better.
Expand All @@ -18,6 +19,7 @@ Low Priority / Cleanup:
- Maybe check for identical presets in the library when adding a new one, but maybe not.
- It would be nice to set the selection back on the updated preset in the library, but that's kind of hard if we're sorting after updating. See what we can do.
- Can the Newtonsoft JSON dll be packaged in with the executable easily?
- Make the waymark and preset get string methods be ToString.


Very Low Priority / Potential New Features:
Expand Down
18 changes: 11 additions & 7 deletions WaymarkLibrarianForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public WaymarkLibrarianForm()
// WinForms Stuff
InitializeComponent();

// Control setup.
// Set up controls.
PresetTimePicker.Format = DateTimePickerFormat.Time;
PresetTimePicker.ShowUpDown = true;

Expand All @@ -40,12 +40,12 @@ public WaymarkLibrarianForm()
mPresetLibrary = new PresetLibrary( mSettings.ConfigFolderPath + "\\WaymarkLibrary.xml" );
PopulateLibraryListBox();

// Initialize the game settings folder, character list, and game preset list.
// Populate the controls for the character config folder, character list, and game preset list based on the saved settings.
if( Directory.Exists( mSettings.ProgramSettings.CharacterDataFolderPath ) )
{
CharacterDataFolderTextBox.Text = mSettings.ProgramSettings.CharacterDataFolderPath;
PopulateCharacterListDropdown();
if( ( mSettings.ProgramSettings.DefaultCharacterID.Length > 0 ) && File.Exists( mSettings.ProgramSettings.CharacterDataFolderPath + '\\' + mSettings.ProgramSettings.DefaultCharacterID + '\\' + mSettings.GameDataSettings.WaymarkDataFileName ) )
if( mSettings.ProgramSettings.DefaultCharacterID.Length > 0 && File.Exists( mSettings.ProgramSettings.CharacterDataFolderPath + '\\' + mSettings.ProgramSettings.DefaultCharacterID + '\\' + mSettings.GameDataSettings.WaymarkDataFileName ) )
{
for( int i = 0; i < CharacterListDropdown.Items.Count; ++i )
{
Expand Down Expand Up @@ -73,8 +73,8 @@ public WaymarkLibrarianForm()
private string[] mCharacterFolderList;
private Config mSettings;

// Class Functions
#region General Helper Functions
// Types
#region Types
// Trivial class to aid with JSON serialiazing. I *hate* serializing objects instead of using an actual config format, but this is probably the best thing to have presets be transferrable between this program and Paisley Park. At least having a buffer object lets us keep the JSON stuff isolated, even if it results in more work for us.
// Some of these fields may be meaningless for this program in order to (maybe) allow Paisley import of our exports.
class PresetExportObject
Expand Down Expand Up @@ -102,8 +102,8 @@ public class WaymarkExportObject
}
#endregion

// Member Functions
#region Event Helper Functions
// Class Functions
#region General Helper Functions
public static bool DynamicObjectPropertyExists( dynamic obj, string name )
{
// Didn't write; came from https://stackoverflow.com/a/48752086;
Expand All @@ -112,6 +112,10 @@ public static bool DynamicObjectPropertyExists( dynamic obj, string name )
if( obj is Newtonsoft.Json.Linq.JObject ) return ( (Newtonsoft.Json.Linq.JObject)obj ).ContainsKey( name );
return obj.GetType().GetProperty( name ) != null;
}
#endregion

// Member Functions
#region Event Helper Functions
private void PopulateCharacterListDropdown()
{
CharacterListDropdown.Items.Clear();
Expand Down
8 changes: 6 additions & 2 deletions ZoneDictionaryGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ static void Main( string[] args )
inFile = Console.ReadLine();
}

// Ask for the game version too.
Console.WriteLine( "Specify the game's version corresponding to this territory info:" );
string gameVersion = Console.ReadLine();

// Read the file in as lines.
List<string> lines = File.ReadLines( inFile ).ToList();

Expand Down Expand Up @@ -54,8 +58,8 @@ static void Main( string[] args )
// Zone ID 0 probably isn't valid for any waymarks, so remove that entry (it's likely been overwritten with duplicates anyway).
zoneDictionary.Remove( 0 );

// Write the dictionary out to file.
string outString = "";
// Write the dictionary out to file. Put the version at the top.
string outString = "GameVersion = " + gameVersion + "\r\n";
foreach( KeyValuePair<UInt16, string> entry in zoneDictionary )
{
outString += entry.Key + " = " + entry.Value + "\r\n";
Expand Down

0 comments on commit 64e9da0

Please sign in to comment.