Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
ok for loading UPlink cli from anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlotronics committed Jan 25, 2020
1 parent 8637fdf commit 231ac9a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
public class CLIUplink
{
string filename;
public CLIUplink(string path=".\\", string filename= "uplink_windows_amd64.exe")
public CLIUplink(string path= ".\\uplink_windows_amd64.exe")
{
string last = path.Substring(path.Length - 1);
if (last != "\\" && last != "/")
path += "\\";
this.filename = path + filename;
this.filename = path;
}

public void test(string cmd)
Expand Down
19 changes: 19 additions & 0 deletions StorjTardigradeWindowsGui/StorjTardigradeWindowsGui/DialogBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,24 @@ public static DialogResult Alert(string title, string message)
DialogResult dialogResult = form.ShowDialog();
return dialogResult;
}

public static string FilePrompt(string title)
{
var filePath = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = @"c:\";
openFileDialog.Filter = "Application files (*.exe)|*.exe|All files (*.*)|*.*";
openFileDialog.RestoreDirectory = true;

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
return filePath;
}

return null;
}
}
}
}
20 changes: 19 additions & 1 deletion StorjTardigradeWindowsGui/StorjTardigradeWindowsGui/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -10,6 +11,7 @@ static class Program
{
public static CLIUplink cli;
public static List<Dictionary<string, string>> Buckets = null;
public static string UplinkCLIPath = @"%userprofile%\storj-uplink\uplink_windows_amd64.exe";
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
Expand All @@ -18,7 +20,22 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
cli = new CLIUplink(@"C:\Users\Charles\storj-uplink");

Tools.LoadSettings();

while(UplinkCLIPath == null || !File.Exists(UplinkCLIPath))
{
if (DialogBox.Alert("Uplink CLI location", "Please select the Uplink CLI file in the following window.") == DialogResult.OK)
{
UplinkCLIPath = DialogBox.FilePrompt("Uplink CLI Path");
}
else
System.Environment.Exit(2);
}
Tools.SaveSettings();

cli = new CLIUplink(UplinkCLIPath);

if (!cli.IsRegistered())
{
if(DialogBox.Alert("Log in to Tardigrade Network", "This client has to be used with Uplink CLI.\nPlease first login using your API token first.\n\nDetailled informations can be found at https://documentation.tardigrade.io/api-reference/uplink-cli.\n\n") == DialogResult.OK)
Expand All @@ -35,6 +52,7 @@ static void Main()
// System.Environment.Exit(1);
}
}

Application.Run(new MainGUI());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>main.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -82,5 +85,8 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="main.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
24 changes: 23 additions & 1 deletion StorjTardigradeWindowsGui/StorjTardigradeWindowsGui/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -20,5 +21,26 @@ internal static void PrintListOfDict(List<Dictionary<string, string>> d)
}
Console.WriteLine();
}

internal static bool LoadSettings()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\StorjTardigradeWindowsGui");
if(key != null)
{
Program.UplinkCLIPath = (string) key.GetValue("UplinkCLIPath");

if (Program.UplinkCLIPath == null)
return false;
return true;
}

return false;
}

internal static void SaveSettings()
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\StorjTardigradeWindowsGui");
key.SetValue("UplinkCLIPath", Program.UplinkCLIPath);
}
}
}

0 comments on commit 231ac9a

Please sign in to comment.