Change Settings to AppConfigSettings, so that it can save the GoogleRefreshToken
Change Settings to AppConfigSettings, so that it can save the GoogleRefreshToken
diff --git a/PokemonGo/RocketAPI/Client.cs b/PokemonGo/RocketAPI/Client.cs
index 474a5db..55f434e 100644
--- a/PokemonGo/RocketAPI/Client.cs
+++ b/PokemonGo/RocketAPI/Client.cs
@@ -57,9 +57,8 @@ namespace PokemonGo.RocketAPI
var tokenResponse = await GoogleLogin.GetAccessToken();
_accessToken = tokenResponse.id_token;
_settings.GoogleRefreshToken = tokenResponse.access_token;
- Console.WriteLine($"Put RefreshToken in settings for direct login: {_settings.GoogleRefreshToken}");
}
- else
+ else
{
var tokenResponse = await GoogleLogin.GetAccessToken(_settings.GoogleRefreshToken);
_accessToken = tokenResponse.id_token;
diff --git a/PokemonGo/RocketAPI/Console/App.config b/PokemonGo/RocketAPI/Console/App.config
index 9459877..fcfe76e 100644
--- a/PokemonGo/RocketAPI/Console/App.config
+++ b/PokemonGo/RocketAPI/Console/App.config
@@ -11,4 +11,12 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
+ <appSettings>
+ <add key="AuthType" value="Google"/>
+ <add key="PtcUsername" value="username"/>
+ <add key="PtcPassword" value="pw"/>
+ <add key="GoogleRefreshToken" value=""/>
+ <add key="DefaultLatitude" value="52.379189"/><!--Default Amsterdam Central Station-->
+ <add key="DefaultLongitude" value="4.899431"/><!--Default Amsterdam Central Station-->
+ </appSettings>
</configuration>
\ No newline at end of file
diff --git a/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj b/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
index 70cf8ed..fafb5f7 100644
--- a/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
+++ b/PokemonGo/RocketAPI/Console/PokemonGo.RocketAPI.Console.csproj
@@ -37,6 +37,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
diff --git a/PokemonGo/RocketAPI/Console/Settings.cs b/PokemonGo/RocketAPI/Console/Settings.cs
index f141edb..e85349f 100644
--- a/PokemonGo/RocketAPI/Console/Settings.cs
+++ b/PokemonGo/RocketAPI/Console/Settings.cs
@@ -1,16 +1,32 @@
-using PokemonGo.RocketAPI.Enums;
+using System.Configuration;
+using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.GeneratedCode;
+using System;
namespace PokemonGo.RocketAPI.Console
{
public class Settings : ISettings
{
- //Fetch these settings from intercepting the /auth call in headers and body (only needed for google auth)
- public AuthType AuthType { get; } = Enums.AuthType.Google;
- public string PtcUsername { get; } = "User";
- public string PtcPassword { get; } = "alligator2";
- public string GoogleRefreshToken { get; set; } = string.Empty;
- public double DefaultLatitude { get; } = 10;
- public double DefaultLongitude { get; } = 10;
+ public AuthType AuthType => (AuthType)Enum.Parse(typeof(AuthType), GetSetting("AuthType"));
+ public string PtcUsername => GetSetting("PtcUsername") != string.Empty ? GetSetting("PtcUsername") : "username";
+ public string PtcPassword => GetSetting("PtcPassword") != string.Empty? GetSetting("PtcPassword") : "password";
+ public double DefaultLatitude => GetSetting("DefaultLatitude") != string.Empty ? double.Parse(GetSetting("DefaultLatitude")) : 52.379189; //Default Amsterdam Central Station
+ public double DefaultLongitude => GetSetting("DefaultLongitude") != string.Empty ? double.Parse(GetSetting("DefaultLongitude")) : 4.899431;//Default Amsterdam Central Station
+ public string GoogleRefreshToken
+ {
+ get { return GetSetting("GoogleRefreshToken") != string.Empty ? GetSetting("GoogleRefreshToken") : string.Empty; }
+ set { SetSetting("GoogleRefreshToken", value); }
+ }
+
+ private string GetSetting(string key)
+ {
+ return ConfigurationManager.AppSettings[key];
+ }
+ private void SetSetting(string key, string value)
+ {
+ var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
+ configFile.AppSettings.Settings[key].Value = value;
+ configFile.Save();
+ }
}
}
You may download the files in Public Git.