Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 40e92c3

Browse files
authored
Merge pull request #19 from entvex/17-starting-the-gui-from-command-prompt
17 starting the gui from command prompt
2 parents 503b11a + a07ac80 commit 40e92c3

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

FirstTimeWizard.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void _ngrokManager_DownloadAndUnZipDone(object sender, EventArgs e)
4949

5050
private void BtnDownload_OnClick(object sender, RoutedEventArgs e)
5151
{
52-
if (btnDownload.Content == "Next")
52+
if ((string)btnDownload.Content == "Next")
5353
{
5454
tabcl.SelectedIndex = 1;
5555
return;

MainWindow.xaml.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public partial class MainWindow : Window
1616
{
1717
private readonly INgrokManager _ngrokManager;
1818
private readonly ObservableCollection<TunnelDescription> _tunnelDescriptions;
19+
private readonly string _downloadFolder =
20+
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar}NgrokSharp{Path.DirectorySeparatorChar}";
1921
private bool PaidAccount;
2022

2123
public MainWindow()
@@ -27,11 +29,18 @@ public MainWindow()
2729

2830
_ngrokManager = new NgrokManager();
2931

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+
3039
Settings settings;
3140
try
3241
{
3342
//Load settings
34-
settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText("Settings.json"));
43+
settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText($"{_downloadFolder}Settings.json"));
3544

3645
if (settings.FirstTimeSetupDone == false)
3746
{
@@ -44,17 +53,18 @@ public MainWindow()
4453
settings.DataCenterRegion = firstTimeWizard.cmbTunnelExit.SelectedIndex;
4554
settings.PaidAccount = (bool) firstTimeWizard.cbxPaidAccount.IsChecked;
4655

47-
File.WriteAllText("Settings.json", JsonConvert.SerializeObject(settings));
56+
File.WriteAllText($"{_downloadFolder}Settings.json", JsonConvert.SerializeObject(settings));
4857
}
4958
}
5059

5160
PaidAccount = settings.PaidAccount;
52-
sbStatus.Content = "connected to " + (NgrokManager.Region)settings.DataCenterRegion;
61+
sbStatus.Content = $"connected to {(NgrokManager.Region)settings.DataCenterRegion}";
5362
_ngrokManager.StartNgrok((NgrokManager.Region)settings.DataCenterRegion);
5463

55-
if (File.Exists("SavedTunnels.json"))
64+
if (File.Exists($"{_downloadFolder}SavedTunnels.json"))
5665
{
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));
5868
}
5969

6070
}
@@ -139,7 +149,7 @@ private void Window_Closed(object sender, EventArgs e)
139149
}
140150
}
141151

142-
File.WriteAllText(@"SavedTunnels.json", JsonConvert.SerializeObject(_tunnelDescriptions));
152+
File.WriteAllText($"{_downloadFolder}SavedTunnels.json", JsonConvert.SerializeObject(_tunnelDescriptions));
143153

144154
}
145155

@@ -177,7 +187,7 @@ private void BtnMenuItemRunFirstTimeWizard_OnClick(object sender, RoutedEventArg
177187
if (result == MessageBoxResult.Yes)
178188
{
179189
Settings settings = new Settings {FirstTimeSetupDone = false};
180-
File.WriteAllText("Settings.json", JsonConvert.SerializeObject(settings));
190+
File.WriteAllText($"{_downloadFolder}Settings.json", JsonConvert.SerializeObject(settings));
181191
Close();
182192
}
183193
}
@@ -235,8 +245,8 @@ private async void btnMenuItemDeleteTunnel_OnClick(object sender, RoutedEventArg
235245
var result = await _ngrokManager.StopTunnel(_tunnelDescriptions[lwTunnels.SelectedIndex].Name);
236246
}
237247

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);
240250

241251
}
242252
}

ngrokGUI.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>net5.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>
77
<ApplicationIcon>icons8-tunnel-256.ico</ApplicationIcon>
8+
<AssemblyName>ngrokGUI</AssemblyName>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -35,10 +36,4 @@
3536
<Resource Include="icons8-tunnel-256.png" />
3637
</ItemGroup>
3738

38-
<ItemGroup>
39-
<None Update="Settings.json">
40-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41-
</None>
42-
</ItemGroup>
43-
4439
</Project>

0 commit comments

Comments
 (0)