@@ -16,6 +16,8 @@ public partial class MainWindow : Window
16
16
{
17
17
private readonly INgrokManager _ngrokManager ;
18
18
private readonly ObservableCollection < TunnelDescription > _tunnelDescriptions ;
19
+ private readonly string _downloadFolder =
20
+ $ "{ Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + Path . DirectorySeparatorChar } NgrokSharp{ Path . DirectorySeparatorChar } ";
19
21
private bool PaidAccount ;
20
22
21
23
public MainWindow ( )
@@ -27,11 +29,18 @@ public MainWindow()
27
29
28
30
_ngrokManager = new NgrokManager ( ) ;
29
31
32
+
33
+ if ( ! File . Exists ( $ "{ _downloadFolder } Settings.json") )
34
+ {
35
+ Directory . CreateDirectory ( _downloadFolder ) ;
36
+ File . WriteAllText ( $ "{ _downloadFolder } Settings.json", "{\r \n \" firstTimeSetupDone\" : false\r \n }" ) ;
37
+ }
38
+
30
39
Settings settings ;
31
40
try
32
41
{
33
42
//Load settings
34
- settings = JsonConvert . DeserializeObject < Settings > ( File . ReadAllText ( " Settings.json") ) ;
43
+ settings = JsonConvert . DeserializeObject < Settings > ( File . ReadAllText ( $ " { _downloadFolder } Settings.json") ) ;
35
44
36
45
if ( settings . FirstTimeSetupDone == false )
37
46
{
@@ -44,17 +53,18 @@ public MainWindow()
44
53
settings . DataCenterRegion = firstTimeWizard . cmbTunnelExit . SelectedIndex ;
45
54
settings . PaidAccount = ( bool ) firstTimeWizard . cbxPaidAccount . IsChecked ;
46
55
47
- File . WriteAllText ( " Settings.json", JsonConvert . SerializeObject ( settings ) ) ;
56
+ File . WriteAllText ( $ " { _downloadFolder } Settings.json", JsonConvert . SerializeObject ( settings ) ) ;
48
57
}
49
58
}
50
59
51
60
PaidAccount = settings . PaidAccount ;
52
- sbStatus . Content = "connected to " + ( NgrokManager . Region ) settings . DataCenterRegion ;
61
+ sbStatus . Content = $ "connected to { ( NgrokManager . Region ) settings . DataCenterRegion } " ;
53
62
_ngrokManager . StartNgrok ( ( NgrokManager . Region ) settings . DataCenterRegion ) ;
54
63
55
- if ( File . Exists ( " SavedTunnels.json") )
64
+ if ( File . Exists ( $ " { _downloadFolder } SavedTunnels.json") )
56
65
{
57
- JsonConvert . DeserializeObject < List < TunnelDescription > > ( File . ReadAllText ( "SavedTunnels.json" ) ) ? . ForEach ( x => _tunnelDescriptions . Add ( x ) ) ;
66
+ JsonConvert . DeserializeObject < List < TunnelDescription > > ( File . ReadAllText (
67
+ $ "{ _downloadFolder } SavedTunnels.json") ) ? . ForEach ( x => _tunnelDescriptions . Add ( x ) ) ;
58
68
}
59
69
60
70
}
@@ -139,7 +149,7 @@ private void Window_Closed(object sender, EventArgs e)
139
149
}
140
150
}
141
151
142
- File . WriteAllText ( @" SavedTunnels.json", JsonConvert . SerializeObject ( _tunnelDescriptions ) ) ;
152
+ File . WriteAllText ( $ " { _downloadFolder } SavedTunnels.json", JsonConvert . SerializeObject ( _tunnelDescriptions ) ) ;
143
153
144
154
}
145
155
@@ -177,7 +187,7 @@ private void BtnMenuItemRunFirstTimeWizard_OnClick(object sender, RoutedEventArg
177
187
if ( result == MessageBoxResult . Yes )
178
188
{
179
189
Settings settings = new Settings { FirstTimeSetupDone = false } ;
180
- File . WriteAllText ( " Settings.json", JsonConvert . SerializeObject ( settings ) ) ;
190
+ File . WriteAllText ( $ " { _downloadFolder } Settings.json", JsonConvert . SerializeObject ( settings ) ) ;
181
191
Close ( ) ;
182
192
}
183
193
}
@@ -235,8 +245,8 @@ private async void btnMenuItemDeleteTunnel_OnClick(object sender, RoutedEventArg
235
245
var result = await _ngrokManager . StopTunnel ( _tunnelDescriptions [ lwTunnels . SelectedIndex ] . Name ) ;
236
246
}
237
247
238
- var tunnel = _tunnelDescriptions . SingleOrDefault ( x => x . Name == _tunnelDescriptions [ lwTunnels . SelectedIndex ] . Name ) ;
239
- _tunnelDescriptions . Remove ( tunnel ) ;
248
+ var tunnel = _tunnelDescriptions . SingleOrDefault ( x => x . Name == _tunnelDescriptions [ lwTunnels . SelectedIndex ] . Name ) ;
249
+ _tunnelDescriptions . Remove ( tunnel ) ;
240
250
241
251
}
242
252
}
0 commit comments