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

Commit

Permalink
Merge pull request #19 from entvex/17-starting-the-gui-from-command-p…
Browse files Browse the repository at this point in the history
…rompt

17 starting the gui from command prompt
  • Loading branch information
entvex authored Oct 19, 2021
2 parents 503b11a + a07ac80 commit 40e92c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion FirstTimeWizard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void _ngrokManager_DownloadAndUnZipDone(object sender, EventArgs e)

private void BtnDownload_OnClick(object sender, RoutedEventArgs e)
{
if (btnDownload.Content == "Next")
if ((string)btnDownload.Content == "Next")
{
tabcl.SelectedIndex = 1;
return;
Expand Down
28 changes: 19 additions & 9 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public partial class MainWindow : Window
{
private readonly INgrokManager _ngrokManager;
private readonly ObservableCollection<TunnelDescription> _tunnelDescriptions;
private readonly string _downloadFolder =
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar}NgrokSharp{Path.DirectorySeparatorChar}";
private bool PaidAccount;

public MainWindow()
Expand All @@ -27,11 +29,18 @@ public MainWindow()

_ngrokManager = new NgrokManager();


if (!File.Exists($"{_downloadFolder}Settings.json"))
{
Directory.CreateDirectory(_downloadFolder);
File.WriteAllText($"{_downloadFolder}Settings.json", "{\r\n \"firstTimeSetupDone\": false\r\n}");
}

Settings settings;
try
{
//Load settings
settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText("Settings.json"));
settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText($"{_downloadFolder}Settings.json"));

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

File.WriteAllText("Settings.json", JsonConvert.SerializeObject(settings));
File.WriteAllText($"{_downloadFolder}Settings.json", JsonConvert.SerializeObject(settings));
}
}

PaidAccount = settings.PaidAccount;
sbStatus.Content = "connected to " + (NgrokManager.Region)settings.DataCenterRegion;
sbStatus.Content = $"connected to {(NgrokManager.Region)settings.DataCenterRegion}";
_ngrokManager.StartNgrok((NgrokManager.Region)settings.DataCenterRegion);

if (File.Exists("SavedTunnels.json"))
if (File.Exists($"{_downloadFolder}SavedTunnels.json"))
{
JsonConvert.DeserializeObject<List<TunnelDescription>>(File.ReadAllText("SavedTunnels.json"))?.ForEach( x => _tunnelDescriptions.Add(x));
JsonConvert.DeserializeObject<List<TunnelDescription>>(File.ReadAllText(
$"{_downloadFolder}SavedTunnels.json"))?.ForEach( x => _tunnelDescriptions.Add(x));
}

}
Expand Down Expand Up @@ -139,7 +149,7 @@ private void Window_Closed(object sender, EventArgs e)
}
}

File.WriteAllText(@"SavedTunnels.json", JsonConvert.SerializeObject(_tunnelDescriptions));
File.WriteAllText($"{_downloadFolder}SavedTunnels.json", JsonConvert.SerializeObject(_tunnelDescriptions));

}

Expand Down Expand Up @@ -177,7 +187,7 @@ private void BtnMenuItemRunFirstTimeWizard_OnClick(object sender, RoutedEventArg
if (result == MessageBoxResult.Yes)
{
Settings settings = new Settings {FirstTimeSetupDone = false};
File.WriteAllText("Settings.json", JsonConvert.SerializeObject(settings));
File.WriteAllText($"{_downloadFolder}Settings.json", JsonConvert.SerializeObject(settings));
Close();
}
}
Expand Down Expand Up @@ -235,8 +245,8 @@ private async void btnMenuItemDeleteTunnel_OnClick(object sender, RoutedEventArg
var result = await _ngrokManager.StopTunnel(_tunnelDescriptions[lwTunnels.SelectedIndex].Name);
}

var tunnel = _tunnelDescriptions.SingleOrDefault(x => x.Name == _tunnelDescriptions[lwTunnels.SelectedIndex].Name);
_tunnelDescriptions.Remove(tunnel);
var tunnel = _tunnelDescriptions.SingleOrDefault(x => x.Name == _tunnelDescriptions[lwTunnels.SelectedIndex].Name);
_tunnelDescriptions.Remove(tunnel);

}
}
Expand Down
7 changes: 1 addition & 6 deletions ngrokGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>icons8-tunnel-256.ico</ApplicationIcon>
<AssemblyName>ngrokGUI</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -35,10 +36,4 @@
<Resource Include="icons8-tunnel-256.png" />
</ItemGroup>

<ItemGroup>
<None Update="Settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>

0 comments on commit 40e92c3

Please sign in to comment.