private void miRemoteSave_Click(object sender, System.EventArgs e) { TheBox.BoxServer.FileTransport msg = new TheBox.BoxServer.FileTransport(); msg.Filename = m_File; Pandora.Profile.Server.FillBoxMessage(msg); msg.Text = m_Text; GenericOK response = Pandora.BoxConnection.ProcessMessage(msg, true) as GenericOK; if (response != null) { // Success sBar.Text = "Remote save succesful"; } else { sBar.Text = "Remote save failed"; } }
/// <summary> /// Deletes a file or folder from the server /// </summary> private void DeleteFromServer() { if (Folder == null) { return; } if (MessageBox.Show(this, Pandora.Localization.TextProvider["Script.ConfirmDel"], "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } TheBox.BoxServer.DeleteRequest msg = new DeleteRequest(); Pandora.Profile.Server.FillBoxMessage(msg); string target = null; if (m_File == null) { target = Folder; } else { target = Path.Combine(Folder, m_File); } msg.Path = target; GenericOK response = Pandora.BoxConnection.ProcessMessage(msg, true) as GenericOK; if (response != null) { sBar.Text = Pandora.Localization.TextProvider["Script.DelOk"]; Tree.Nodes.Remove(Tree.SelectedNode); } else { sBar.Text = Pandora.Localization.TextProvider["Script.DelErr"]; } }
/// <summary> /// Renames an item /// </summary> private void Tree_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { if (m_CreateFolder) { m_CreateFolder = false; // Create new folder if (e.Label == null || e.Label.Length == 0) { e.CancelEdit = true; Tree.Nodes.Remove(e.Node); return; } TheBox.BoxServer.CreateFolder msg = new CreateFolder(); Pandora.Profile.Server.FillBoxMessage(msg); string[] path = Folder.Split(Path.DirectorySeparatorChar); string parentpath = ""; int end = path.Length - 1; if (Folder.EndsWith(Path.DirectorySeparatorChar.ToString())) { end--; } for (int i = 0; i < end; i++) { parentpath += path[i] + Path.DirectorySeparatorChar; } msg.Folder = Path.Combine(parentpath, e.Label); GenericOK response = Pandora.BoxConnection.ProcessMessage(msg, true) as GenericOK; if (response != null) { // Success sBar.Text = Pandora.Localization.TextProvider["Script.CrateOk"]; e.Node.Text = e.Label; txFolder.Text = GetFolder(e.Node); } else { sBar.Text = Pandora.Localization.TextProvider["Script.CreateFail"]; e.CancelEdit = true; Tree.Nodes.Remove(e.Node); } } else { // Rename item if (Folder == null) { return; } if (e.Label == null || e.Label.Length == 0) { e.CancelEdit = true; return; } string old = null; if (m_File == null) { old = Folder; } else { old = Path.Combine(Folder, m_File); } TheBox.BoxServer.MoveRequest msg = new MoveRequest(); Pandora.Profile.Server.FillBoxMessage(msg); msg.OldPath = old; msg.NewPath = Path.Combine(Folder, e.Label); GenericOK response = Pandora.BoxConnection.ProcessMessage(msg, true) as GenericOK; if (response != null) { // Success sBar.Text = Pandora.Localization.TextProvider["Script.RenOk"]; e.Node.Text = e.Label; txFolder.Text = GetFolder(e.Node); } else { sBar.Text = Pandora.Localization.TextProvider["Script.RenFail"]; e.CancelEdit = true; } } }
/// <summary> /// Uploads a file to the server /// </summary> private void Upload() { if (Folder == null) { return; } if (OpenFile.ShowDialog() != DialogResult.OK) { return; } string filename = Path.Combine(Folder, Path.GetFileName(OpenFile.FileName)); TheBox.BoxServer.FileTransport msg = new FileTransport(); msg.Filename = filename; Pandora.Profile.Server.FillBoxMessage(msg); // Read text from the file try { StreamReader reader = new StreamReader(OpenFile.FileName); msg.Text = reader.ReadToEnd(); reader.Close(); } catch (Exception err) { Pandora.Log.WriteError(err, "Error when reading text file {0}", OpenFile.FileName); sBar.Text = Pandora.Localization.TextProvider["Script.ReadErr"]; return; } GenericOK response = Pandora.BoxConnection.ProcessMessage(msg, true) as GenericOK; if (response != null) { // Success sBar.Text = Pandora.Localization.TextProvider["Script.UploadOk"]; // Add item TreeNode node = GetTreeNode(Path.GetFileName(OpenFile.FileName)); TreeNode parent = null; if (m_File == null) { parent = Tree.SelectedNode; } else { parent = Tree.SelectedNode.Parent; } bool exists = false; foreach (TreeNode exist in parent.Nodes) { if (exist.Text.ToLower() == node.Text.ToLower()) { exists = true; break; } } if (!exists) { parent.Nodes.Add(node); } } else { sBar.Text = Pandora.Localization.TextProvider["Script.UploadFail"]; } }