2424using Newtonsoft . Json . Linq ;
2525using LibGit2Sharp ;
2626using ORTS . Common ;
27+ using System . Windows . Forms ;
2728
2829namespace ORTS . Settings
2930{
3031 public class RouteSettings
3132 {
33+
34+
3235 public enum DownloadType
3336 {
3437 github ,
@@ -123,20 +126,32 @@ public void Load()
123126 // left empty
124127 }
125128
129+ private string RouteJsonName ;
130+
126131 public void LoadContentAndInstalled ( )
127132 {
128- if ( ! string . IsNullOrWhiteSpace ( Content . RouteJsonName ) )
133+ // set json route filename
134+
135+ string userDataSettingsFolder = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , Application . ProductName , "Settings" ) ;
136+ if ( ! Directory . Exists ( userDataSettingsFolder ) )
137+ {
138+ Directory . CreateDirectory ( userDataSettingsFolder ) ;
139+ }
140+
141+ RouteJsonName = Path . Combine ( userDataSettingsFolder , "ORRoute.json" ) ;
142+
143+ if ( ! string . IsNullOrWhiteSpace ( RouteJsonName ) )
129144 {
130- if ( File . Exists ( Content . RouteJsonName ) )
145+ if ( File . Exists ( RouteJsonName ) )
131146 {
132147 try
133148 {
134- string json = File . ReadAllText ( Content . RouteJsonName ) ;
149+ string json = File . ReadAllText ( RouteJsonName ) ;
135150 Routes = JsonConvert . DeserializeObject < IDictionary < string , Route > > ( json ) ;
136151 }
137152 catch ( Exception error )
138153 {
139- throw new Exception ( "Error during reading " + Content . RouteJsonName + ": " + error . Message , error ) ;
154+ throw new Exception ( "Error during reading " + RouteJsonName + ": " + error . Message , error ) ;
140155 }
141156 }
142157 }
@@ -162,7 +177,7 @@ public void LoadContentAndInstalled()
162177 }
163178 catch ( Exception error )
164179 {
165- throw new Exception ( "Error during retrieving routes.json from \" " + githubUrl + "\" :" + error . Message , error ) ;
180+ throw new Exception ( "Error during retrieving routes.json from \" " + githubUrl + "\" : " + error . Message , error ) ;
166181 }
167182 }
168183
@@ -281,7 +296,7 @@ public void Save()
281296 }
282297 }
283298 string json = JsonConvert . SerializeObject ( routes , Formatting . Indented ) ;
284- File . WriteAllText ( Content . RouteJsonName , json ) ;
299+ File . WriteAllText ( RouteJsonName , json ) ;
285300 }
286301 }
287302}
0 commit comments