-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Launcher Preferences are now saved and loaded
- Loading branch information
1 parent
0c8fa39
commit a3c22ff
Showing
8 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ZenovaLauncher | ||
{ | ||
public class NotifyPropertyChangedBase : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected void OnPropertyChanged(string name) | ||
{ | ||
if (PropertyChanged != null) | ||
PropertyChanged(this, new PropertyChangedEventArgs(name)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ZenovaLauncher | ||
{ | ||
public class Preferences : NotifyPropertyChangedBase | ||
{ | ||
public static Preferences instance; | ||
|
||
private static string _preferencesFile = "preferences.json"; | ||
private static JsonSerializerSettings camelCaseSerialization; | ||
|
||
public bool EnableReleases { get; set; } | ||
public bool EnableBetas { get; set; } | ||
public bool EnableHistorical { get; set; } | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public Profile.ProfileSortType ProfileSorting { get; set; } | ||
[JsonIgnore] | ||
public int ProfileSortingId | ||
{ | ||
get { return (int)ProfileSorting; } | ||
set { ProfileSorting = (Profile.ProfileSortType)value; } | ||
} | ||
|
||
|
||
public static void LoadPreferences(string dataDir) | ||
{ | ||
_preferencesFile = Path.Combine(dataDir, _preferencesFile); | ||
camelCaseSerialization = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; | ||
if (File.Exists(_preferencesFile)) | ||
{ | ||
instance = JsonConvert.DeserializeObject<Preferences>(File.ReadAllText(_preferencesFile), camelCaseSerialization); | ||
} | ||
else | ||
{ | ||
instance = new Preferences(); | ||
instance.SetDefaultPreferences(); | ||
} | ||
} | ||
|
||
public static void SavePreferences() | ||
{ | ||
File.WriteAllText(_preferencesFile, JsonConvert.SerializeObject(instance, Formatting.Indented, camelCaseSerialization)); | ||
} | ||
|
||
public void SetDefaultPreferences() | ||
{ | ||
EnableReleases = true; | ||
EnableBetas = false; | ||
EnableHistorical = false; | ||
ProfileSorting = Profile.ProfileSortType.ByLastPlayed; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters