Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give json settings the touch #581

Merged
1 commit merged into from Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static void Main()

machine.SetFailureState(new LoginState());

GlobalSettings settings = GlobalSettings.Load("\\config\\config.json");
GlobalSettings settings = GlobalSettings.Load("\\configs\\config.json");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep config, people are going to lose their temper if we keep changing the directory :p


var context = new Context(new ClientSettings(settings), new LogicSettings(settings));
context.Client.Login.GoogleDeviceCodeEvent += LoginWithGoogle;
Expand Down
30 changes: 15 additions & 15 deletions PoGo.NecroBot.CLI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ namespace PoGo.NecroBot.CLI
{
internal class AuthSettings
{
//Default Auth Settings
public AuthType AuthType = AuthType.Google;
public string GoogleRefreshToken = "";
public string PtcPassword = "username2";
public string PtcUsername = "pw";

[JsonIgnore]
private string FilePath;
private string _filePath;

public void Load(string path)
{
FilePath = path;
_filePath = path;

if (File.Exists(FilePath))
if (File.Exists(_filePath))
{
//if the file exists, load the settings
var input = File.ReadAllText(FilePath);
var input = File.ReadAllText(_filePath);

JsonSerializerSettings settings = new JsonSerializerSettings();
settings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
Expand All @@ -43,7 +43,7 @@ public void Load(string path)
}
else
{
Save(FilePath);
Save(_filePath);
}
}

Expand All @@ -62,9 +62,9 @@ public void Save(string path)

public void Save()
{
if(!string.IsNullOrEmpty(FilePath))
if(!string.IsNullOrEmpty(_filePath))
{
Save(FilePath);
Save(_filePath);
}
}
}
Expand All @@ -73,6 +73,9 @@ public class GlobalSettings
{
public static GlobalSettings Default => new GlobalSettings();

[JsonIgnore]
internal AuthSettings Auth = new AuthSettings();

private static string GetAuthPath(string path)
{
var fullPath = Directory.GetCurrentDirectory() + path;
Expand All @@ -89,7 +92,6 @@ public static GlobalSettings Load(string path)
GlobalSettings settings = null;
if (File.Exists(fullPath))
{
//if the file exists, load the settings
var input = File.ReadAllText(fullPath);

JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
Expand Down Expand Up @@ -123,6 +125,7 @@ public void Save(string path)
File.WriteAllText(fullPath, output);
}

//Default Global Settings
public double DefaultAltitude = 10;
public double DefaultLatitude = 52.379189;
public double DefaultLongitude = 4.899431;
Expand All @@ -142,10 +145,7 @@ public void Save(string path)
public bool UseLuckyEggsWhileEvolving = false;
public bool UsePokemonToNotCatchFilter = false;
public double WalkingSpeedInKilometerPerHour = 50;

[JsonIgnore]
internal AuthSettings Auth = new AuthSettings();


public List<KeyValuePair<ItemId, int>> ItemRecycleFilter = new List<KeyValuePair<ItemId, int>>
{
new KeyValuePair<ItemId, int>(ItemId.ItemUnknown, 0),
Expand Down Expand Up @@ -208,7 +208,7 @@ public void Save(string path)

public class ClientSettings : ISettings
{
private GlobalSettings _settings;
private readonly GlobalSettings _settings;

public ClientSettings(GlobalSettings settings)
{
Expand Down Expand Up @@ -238,7 +238,7 @@ public string GoogleRefreshToken

public class LogicSettings : ILogicSettings
{
private GlobalSettings _settings;
private readonly GlobalSettings _settings;

public LogicSettings(GlobalSettings settings)
{
Expand Down