|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.ComponentModel; |
4 |
| -using System.Data; |
5 |
| -using System.Drawing; |
6 |
| -using System.Linq; |
7 |
| -using System.Text; |
8 |
| -using System.Windows.Forms; |
9 |
| -using System.IO; |
10 |
| - |
11 |
| -namespace SteamCloudFileManager |
12 |
| -{ |
13 |
| - public partial class MainForm : Form |
14 |
| - { |
15 |
| - IRemoteStorage storage; |
16 |
| - |
17 |
| - public MainForm() |
18 |
| - { |
19 |
| - InitializeComponent(); |
20 |
| - } |
21 |
| - |
22 |
| - private void connectButton_Click(object sender, EventArgs e) |
23 |
| - { |
24 |
| - try |
25 |
| - { |
26 |
| - storage = RemoteStorage.CreateInstance(uint.Parse(appIdTextBox.Text)); |
27 |
| - //storage = new RemoteStorageLocal("remote", uint.Parse(appIdTextBox.Text)); |
28 |
| - refreshButton.Enabled = true; |
29 |
| - refreshButton_Click(this, EventArgs.Empty); |
30 |
| - } |
31 |
| - catch (Exception ex) |
32 |
| - { |
33 |
| - MessageBox.Show(this, ex.ToString(), "Failed to connect", MessageBoxButtons.OK, MessageBoxIcon.Error); |
34 |
| - } |
35 |
| - } |
36 |
| - |
37 |
| - private void refreshButton_Click(object sender, EventArgs e) |
38 |
| - { |
39 |
| - if (storage == null) |
40 |
| - { |
41 |
| - MessageBox.Show(this, "Not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
42 |
| - return; |
43 |
| - } |
44 |
| - |
45 |
| - try |
46 |
| - { |
47 |
| - List<IRemoteFile> files = storage.GetFiles(); |
48 |
| - remoteListView.Items.Clear(); |
49 |
| - foreach (IRemoteFile file in files) |
50 |
| - { |
51 |
| - ListViewItem itm = new ListViewItem(new string[] { file.Name, file.Timestamp.ToString(), file.Size.ToString(), file.IsPersisted.ToString(), file.Exists.ToString() }) { Tag = file }; |
52 |
| - remoteListView.Items.Add(itm); |
53 |
| - } |
54 |
| - updateQuota(); |
55 |
| - } |
56 |
| - catch (Exception ex) |
57 |
| - { |
58 |
| - MessageBox.Show(this, "Can't refresh." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
59 |
| - } |
60 |
| - } |
61 |
| - |
62 |
| - void updateQuota() |
63 |
| - { |
64 |
| - if (storage == null) throw new InvalidOperationException("Not connected"); |
65 |
| - int totalBytes, availBytes; |
66 |
| - storage.GetQuota(out totalBytes, out availBytes); |
67 |
| - quotaLabel.Text = string.Format("{0}/{1} bytes used", totalBytes - availBytes, totalBytes); |
68 |
| - } |
69 |
| - |
70 |
| - private void downloadButton_Click(object sender, EventArgs e) |
71 |
| - { |
72 |
| - if (storage == null) |
73 |
| - { |
74 |
| - MessageBox.Show(this, "Not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
75 |
| - return; |
76 |
| - } |
77 |
| - if (remoteListView.SelectedIndices.Count != 1) |
78 |
| - { |
79 |
| - MessageBox.Show(this, "Please select only one file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
80 |
| - return; |
81 |
| - } |
82 |
| - |
83 |
| - IRemoteFile file = remoteListView.SelectedItems[0].Tag as IRemoteFile; |
84 |
| - saveFileDialog1.FileName = Path.GetFileName(file.Name); |
85 |
| - if (saveFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) |
86 |
| - { |
87 |
| - try |
88 |
| - { |
89 |
| - File.WriteAllBytes(saveFileDialog1.FileName, file.ReadAllBytes()); |
90 |
| - MessageBox.Show(this, "File downloaded.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); |
91 |
| - } |
92 |
| - catch (Exception ex) |
93 |
| - { |
94 |
| - MessageBox.Show(this, "File download failed." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
95 |
| - } |
96 |
| - } |
97 |
| - } |
98 |
| - |
99 |
| - private void deleteButton_Click(object sender, EventArgs e) |
100 |
| - { |
101 |
| - if (storage == null) |
102 |
| - { |
103 |
| - MessageBox.Show(this, "Not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
104 |
| - return; |
105 |
| - } |
106 |
| - if (remoteListView.SelectedIndices.Count == 0) |
107 |
| - { |
108 |
| - MessageBox.Show(this, "Please select files to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
109 |
| - return; |
110 |
| - } |
111 |
| - |
112 |
| - if (MessageBox.Show(this, "Are you sure you want to delete the selected files?", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No) return; |
113 |
| - |
114 |
| - bool allSuccess = true; |
115 |
| - |
116 |
| - foreach (ListViewItem item in remoteListView.SelectedItems) |
117 |
| - { |
118 |
| - IRemoteFile file = item.Tag as IRemoteFile; |
119 |
| - try |
120 |
| - { |
121 |
| - bool success = file.Delete(); |
122 |
| - if (!success) |
123 |
| - { |
124 |
| - allSuccess = false; |
125 |
| - MessageBox.Show(this, file.Name + " failed to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
126 |
| - } |
127 |
| - else |
128 |
| - { |
129 |
| - item.Remove(); |
130 |
| - } |
131 |
| - } |
132 |
| - catch (Exception ex) |
133 |
| - { |
134 |
| - MessageBox.Show(this, file.Name + " failed to delete." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
135 |
| - } |
136 |
| - } |
137 |
| - |
138 |
| - updateQuota(); |
139 |
| - if (allSuccess) MessageBox.Show(this, "Files deleted.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); |
140 |
| - } |
141 |
| - |
142 |
| - private void remoteListView_SelectedIndexChanged(object sender, EventArgs e) |
143 |
| - { |
144 |
| - downloadButton.Enabled = deleteButton.Enabled = (storage != null && remoteListView.SelectedIndices.Count > 0); |
145 |
| - } |
146 |
| - } |
147 |
| -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Data; |
| 5 | +using System.Drawing; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Windows.Forms; |
| 9 | +using System.IO; |
| 10 | + |
| 11 | +namespace SteamCloudFileManager |
| 12 | +{ |
| 13 | + public partial class MainForm : Form |
| 14 | + { |
| 15 | + IRemoteStorage storage; |
| 16 | + |
| 17 | + public MainForm() |
| 18 | + { |
| 19 | + InitializeComponent(); |
| 20 | + } |
| 21 | + |
| 22 | + private void connectButton_Click(object sender, EventArgs e) |
| 23 | + { |
| 24 | + try |
| 25 | + { |
| 26 | + uint appId; |
| 27 | + if (string.IsNullOrWhiteSpace(appIdTextBox.Text)) |
| 28 | + { |
| 29 | + MessageBox.Show(this, "Please enter an App ID.", "Failed to connect", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 30 | + return; |
| 31 | + } |
| 32 | + if (!uint.TryParse(appIdTextBox.Text.Trim(), out appId)) |
| 33 | + { |
| 34 | + MessageBox.Show(this, "Please make sure the App ID you entered is valid.", "Failed to connect", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 35 | + return; |
| 36 | + } |
| 37 | + storage = RemoteStorage.CreateInstance(uint.Parse(appIdTextBox.Text)); |
| 38 | + //storage = new RemoteStorageLocal("remote", uint.Parse(appIdTextBox.Text)); |
| 39 | + refreshButton.Enabled = true; |
| 40 | + refreshButton_Click(this, EventArgs.Empty); |
| 41 | + } |
| 42 | + catch (Exception ex) |
| 43 | + { |
| 44 | + MessageBox.Show(this, ex.ToString(), "Failed to connect", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + private void refreshButton_Click(object sender, EventArgs e) |
| 49 | + { |
| 50 | + if (storage == null) |
| 51 | + { |
| 52 | + MessageBox.Show(this, "Not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + try |
| 57 | + { |
| 58 | + List<IRemoteFile> files = storage.GetFiles(); |
| 59 | + remoteListView.Items.Clear(); |
| 60 | + foreach (IRemoteFile file in files) |
| 61 | + { |
| 62 | + ListViewItem itm = new ListViewItem(new string[] { file.Name, file.Timestamp.ToString(), file.Size.ToString(), file.IsPersisted.ToString(), file.Exists.ToString() }) { Tag = file }; |
| 63 | + remoteListView.Items.Add(itm); |
| 64 | + } |
| 65 | + updateQuota(); |
| 66 | + } |
| 67 | + catch (Exception ex) |
| 68 | + { |
| 69 | + MessageBox.Show(this, "Can't refresh." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + void updateQuota() |
| 74 | + { |
| 75 | + if (storage == null) throw new InvalidOperationException("Not connected"); |
| 76 | + int totalBytes, availBytes; |
| 77 | + storage.GetQuota(out totalBytes, out availBytes); |
| 78 | + quotaLabel.Text = string.Format("{0}/{1} bytes used", totalBytes - availBytes, totalBytes); |
| 79 | + } |
| 80 | + |
| 81 | + private void downloadButton_Click(object sender, EventArgs e) |
| 82 | + { |
| 83 | + if (storage == null) |
| 84 | + { |
| 85 | + MessageBox.Show(this, "Not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 86 | + return; |
| 87 | + } |
| 88 | + if (remoteListView.SelectedIndices.Count != 1) |
| 89 | + { |
| 90 | + MessageBox.Show(this, "Please select only one file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + IRemoteFile file = remoteListView.SelectedItems[0].Tag as IRemoteFile; |
| 95 | + saveFileDialog1.FileName = Path.GetFileName(file.Name); |
| 96 | + if (saveFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) |
| 97 | + { |
| 98 | + try |
| 99 | + { |
| 100 | + File.WriteAllBytes(saveFileDialog1.FileName, file.ReadAllBytes()); |
| 101 | + MessageBox.Show(this, "File downloaded.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 102 | + } |
| 103 | + catch (Exception ex) |
| 104 | + { |
| 105 | + MessageBox.Show(this, "File download failed." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + private void deleteButton_Click(object sender, EventArgs e) |
| 111 | + { |
| 112 | + if (storage == null) |
| 113 | + { |
| 114 | + MessageBox.Show(this, "Not connected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 115 | + return; |
| 116 | + } |
| 117 | + if (remoteListView.SelectedIndices.Count == 0) |
| 118 | + { |
| 119 | + MessageBox.Show(this, "Please select files to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 120 | + return; |
| 121 | + } |
| 122 | + |
| 123 | + if (MessageBox.Show(this, "Are you sure you want to delete the selected files?", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No) return; |
| 124 | + |
| 125 | + bool allSuccess = true; |
| 126 | + |
| 127 | + foreach (ListViewItem item in remoteListView.SelectedItems) |
| 128 | + { |
| 129 | + IRemoteFile file = item.Tag as IRemoteFile; |
| 130 | + try |
| 131 | + { |
| 132 | + bool success = file.Delete(); |
| 133 | + if (!success) |
| 134 | + { |
| 135 | + allSuccess = false; |
| 136 | + MessageBox.Show(this, file.Name + " failed to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 137 | + } |
| 138 | + else |
| 139 | + { |
| 140 | + item.Remove(); |
| 141 | + } |
| 142 | + } |
| 143 | + catch (Exception ex) |
| 144 | + { |
| 145 | + MessageBox.Show(this, file.Name + " failed to delete." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + updateQuota(); |
| 150 | + if (allSuccess) MessageBox.Show(this, "Files deleted.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| 151 | + } |
| 152 | + |
| 153 | + private void remoteListView_SelectedIndexChanged(object sender, EventArgs e) |
| 154 | + { |
| 155 | + downloadButton.Enabled = deleteButton.Enabled = (storage != null && remoteListView.SelectedIndices.Count > 0); |
| 156 | + } |
| 157 | + } |
| 158 | +} |
0 commit comments