Skip to content

Commit

Permalink
Implement rudimentary upload support
Browse files Browse the repository at this point in the history
  • Loading branch information
GMMan committed Apr 21, 2017
1 parent c1f2f55 commit 154b320
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 20 deletions.
58 changes: 38 additions & 20 deletions SteamCloudFileManager/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions SteamCloudFileManager/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace SteamCloudFileManager
public partial class MainForm : Form
{
IRemoteStorage storage;
// Item1 = cloud name, Item2 = path on disk
Queue<Tuple<string, string>> uploadQueue = new Queue<Tuple<string, string>>();

public MainForm()
{
Expand Down Expand Up @@ -154,5 +156,74 @@ private void remoteListView_SelectedIndexChanged(object sender, EventArgs e)
{
downloadButton.Enabled = deleteButton.Enabled = (storage != null && remoteListView.SelectedIndices.Count > 0);
}

private void uploadBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = (BackgroundWorker)sender;
List<string> failedFiles = new List<string>();
while (uploadQueue.Count > 0)
{
var uploadItem = uploadQueue.Dequeue();
IRemoteFile file = storage.GetFile(uploadItem.Item1);
try
{
byte[] data = File.ReadAllBytes(uploadItem.Item2);
if (!file.WriteAllBytes(data))
failedFiles.Add(uploadItem.Item1);
}
catch (IOException ex)
{
failedFiles.Add(uploadItem.Item1);
}
}

e.Result = failedFiles;
}

private void uploadButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
disableUploadGui();
foreach (var selectedFile in openFileDialog1.FileNames)
{
uploadQueue.Enqueue(new Tuple<string, string>(Path.GetFileName(selectedFile).ToLowerInvariant(), selectedFile));
}
uploadBackgroundWorker.RunWorkerAsync();
}
}

void disableUploadGui()
{
// Disables app switching, refresh, and upload button
connectButton.Enabled = false;
refreshButton.Enabled = false;
uploadButton.Enabled = false;
uploadButton.Text = "Uploading...";
}

void enableUploadGui()
{
connectButton.Enabled = true;
refreshButton.Enabled = true;
uploadButton.Enabled = true;
uploadButton.Text = "Upload";
}

private void uploadBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
var failedList = e.Result as List<string>;
if (failedList.Count == 0)
{
MessageBox.Show(this, "Upload complete.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
failedList.Insert(0, "The following files have failed to upload:");
MessageBox.Show(this, string.Join(Environment.NewLine, failedList), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
enableUploadGui();
refreshButton_Click(this, EventArgs.Empty);
}
}
}
3 changes: 3 additions & 0 deletions SteamCloudFileManager/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>153, 17</value>
</metadata>
<metadata name="uploadBackgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>320, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>63</value>
</metadata>
Expand Down

0 comments on commit 154b320

Please sign in to comment.