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

Commit

Permalink
GUI functions for managing files inside bucket + GUI mapping\
Browse files Browse the repository at this point in the history
Now supports basic files functions inside bucket
  • Loading branch information
Carlotronics committed Jan 26, 2020
1 parent 7122352 commit 874b94d
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 55 deletions.
41 changes: 30 additions & 11 deletions StorjTardigradeWindowsGui/StorjTardigradeWindowsGui/CLI-uplink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private List<String> RunCommand(string cmd, bool RedirectStandardOutput=true)
// p.StartInfo = startInfo;
p.StartInfo.RedirectStandardOutput = RedirectStandardOutput;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = false;
p.Start();

/*
Expand Down Expand Up @@ -93,6 +94,10 @@ public List<Dictionary<string, string>> ListBuckets()
List<String> outp = this.RunCommand(cmd);

List<Dictionary<string, string>> final = new List<Dictionary<string, string>>();

if (outp.Count == 1 && outp[0].Equals("No buckets"))
return final;

foreach (string line in outp)
{
Dictionary<string, string> d = new Dictionary<string, string>();
Expand All @@ -114,7 +119,7 @@ public List<Dictionary<string, string>> ListBuckets()

public List<Dictionary<string, string>> ListFilesInBucket(string bucketName)
{
string cmd = "ls sj://" + bucketName + "/";
string cmd = "ls \"sj://" + bucketName + "/\"";
List<String> outp = this.RunCommand(cmd);

List<Dictionary<string, string>> final = new List<Dictionary<string, string>>();
Expand All @@ -140,7 +145,7 @@ public List<Dictionary<string, string>> ListFilesInBucket(string bucketName)

public bool CreateBucket(string name)
{
string cmd = "mb sj://" + name + "/";
string cmd = "mb \"sj://" + name + "/\"";
List<String> outp = this.RunCommand(cmd);
if (outp.Count == 0)
return false;
Expand All @@ -149,18 +154,32 @@ public bool CreateBucket(string name)

public bool DeleteBucket(string name)
{
string cmd = "rb sj://" + name + "/";
string cmd = "rb \"sj://" + name + "/\"";
List<String> outp = this.RunCommand(cmd);
if (outp.Count == 0)
return false;
return true;
}

public void UploadToBucket(string bucket, string localFilename, string distantFilename="")
{
string cmd = "cp \""+localFilename+"\" \"sj://"+bucket+"/"+distantFilename+"\"";

// List<String> outp =
this.RunCommand(cmd, false);
/*
if (outp.Count == 0)
return false;
return true;
*/
}

public bool RemoveFromBucket(string bucket, string filename)
{
string cmd = "rm \"sj://" + bucket + "/" + filename + "\"";
List<String> outp = this.RunCommand(cmd);
if (outp.Count == 0)
return false;
return true;
}

// TODO
public void UploadToBucket()
{ }

// TODO
public void RemoveFromBucket()
{ }
}
50 changes: 47 additions & 3 deletions StorjTardigradeWindowsGui/StorjTardigradeWindowsGui/DialogBox.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.Text;
Expand All @@ -11,6 +12,8 @@ namespace StorjTardigradeWindowsGui

public static class DialogBox
{
internal static string lastPath = @"C:\";

public static DialogResult Prompt(string title, string promptText, ref string value)
{
Form form = new Form();
Expand Down Expand Up @@ -90,18 +93,59 @@ public static DialogResult Alert(string title, string message)
return dialogResult;
}

public static string FilePrompt(string title)
public static DialogResult Confirm(string title, string message, string text_OK= "OK", string text_cancel= "Cancel")
{
Form form = new Form();
Label label = new Label();
Button buttonOk = new Button();
Button buttonCancel = new Button();

form.Text = title;
label.Text = message;

buttonOk.Text = text_OK;
buttonCancel.Text = text_cancel;
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;

label.SetBounds(9, 20, 372, 13);
buttonOk.SetBounds(228, 100, 75, 23);
buttonCancel.SetBounds(309, 100, 75, 23);

label.AutoSize = true;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

form.ClientSize = new Size(396, 130);
form.Controls.AddRange(new Control[] { label, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;

DialogResult dialogResult = form.ShowDialog();
return dialogResult;
}

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

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
lastPath = Path.GetDirectoryName(filePath);
Tools.SaveSettings();
return filePath;
}

Expand Down
Loading

0 comments on commit 874b94d

Please sign in to comment.