/// <summary> /// Modifies file creation information. If you wish to specify a new file size, use SetFileSize instead. /// </summary> /// <param name="fileName">File name.</param> /// <param name="info">File information.</param> public void SetFileInformation(string fileName, FileInformation info) { uint createhi = (uint)(info.CreationTime.ToFileTime() >> 32); uint createlo = (uint)(info.CreationTime.ToFileTime() & 0xFFFFFFFF); uint changehi = (uint)(info.ChangeTime.ToFileTime() >> 32); uint changelo = (uint)(info.ChangeTime.ToFileTime() & 0xFFFFFFFF); string attr = string.Empty; if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) attr += "readonly=1"; else attr += "readonly=0"; if ((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) attr += "hidden=1"; else attr += "hidden=0"; SendCommand("setfileattributes name=\"{0}\" createhi=0x{1} createlo=0x{2} changehi=0x{3} changelo=0x{4} {5}", fileName, Convert.ToString(createhi, 16), Convert.ToString(createlo, 16), Convert.ToString(changehi, 16), Convert.ToString(changelo, 16), attr); }
/// <summary> /// Retrieves files that belong to a given directory. /// </summary> /// <param name="name">Directory name.</param> /// <returns>List of files.</returns> public List<FileInformation> GetDirectoryList(string name) { List<FileInformation> files = new List<FileInformation>(); StatusResponse response = SendCommand("dirlist name=\"{0}\"", name); if (response.Type == ResponseType.MultiResponse) { string msg = ReceiveSocketLine(); while (msg[0] != '.') { FileInformation info = new FileInformation(); info.Name = msg.Substring(msg.IndexOf("\"") + 1, msg.LastIndexOf("\"") - msg.IndexOf("\"") - 1); // devs f****d up size output so we need to parse carefully... ;X int sizehistart = msg.IndexOf("sizehi") + 9; int sizehiend = msg.IndexOf("sizelo") - 1; int sizelostart = sizehiend + 10; int sizeloend = msg.IndexOf("createhi") - 1; info.Size = Convert.ToUInt64(msg.Substring(sizelostart, sizeloend - sizelostart), 16); info.Size |= (Convert.ToUInt64(msg.Substring(sizehistart, sizehiend - sizehistart), 16) << 32); ulong createtime; createtime = Convert.ToUInt64(msg.Substring(msg.IndexOf("createlo") + 11, 8), 16); createtime |= (Convert.ToUInt64(msg.Substring(msg.IndexOf("createhi") + 11, 8), 16) << 32); info.CreationTime = DateTime.FromFileTime((long)createtime); ulong changetime; changetime = Convert.ToUInt64(msg.Substring(msg.IndexOf("changelo") + 11, 8), 16); changetime |= (Convert.ToUInt64(msg.Substring(msg.IndexOf("changehi") + 11, 8), 16) << 32); info.ChangeTime = DateTime.FromFileTime((long)changetime); if (msg.Contains("directory")) info.Attributes |= FileAttributes.Directory; else info.Attributes |= FileAttributes.Normal; if (msg.Contains("readonly")) info.Attributes |= FileAttributes.ReadOnly; if (msg.Contains("hidden")) info.Attributes |= FileAttributes.Hidden; files.Add(info); msg = ReceiveSocketLine(); } } return files; }
/// <summary> /// Retrieves file information. /// </summary> /// <param name="fileName">File name.</param> /// <returns>File information.</returns> public FileInformation GetFileInformation(string fileName) { FileInformation info = new FileInformation(); info.Name = fileName; SendCommand("getfileattributes name=\"{0}\"", fileName); string msg = ReceiveMultilineResponse(); // devs f****d up size output so we need to parse carefully... ;X int sizehiend = msg.IndexOf("sizelo") - 1; int sizelostart = sizehiend + 10; int sizeloend = msg.IndexOf("createhi") - 1; info.Size = Convert.ToUInt64(msg.Substring(sizelostart, sizeloend - sizelostart), 16); info.Size |= (Convert.ToUInt64(msg.Substring(9, sizehiend - 9), 16) << 32); // should be 0 ulong createtime; createtime = Convert.ToUInt64(msg.Substring(msg.IndexOf("createlo") + 11, 8), 16); createtime |= (Convert.ToUInt64(msg.Substring(msg.IndexOf("createhi") + 11, 8), 16) << 32); info.CreationTime = DateTime.FromFileTime((long)createtime); ulong changetime; changetime = Convert.ToUInt64(msg.Substring(msg.IndexOf("changelo") + 11, 8), 16); changetime |= (Convert.ToUInt64(msg.Substring(msg.IndexOf("changehi") + 11, 8), 16) << 32); info.ChangeTime = DateTime.FromFileTime((long)changetime); if (msg.Contains("directory")) info.Attributes |= FileAttributes.Directory; else info.Attributes |= FileAttributes.Normal; if (msg.Contains("readonly")) info.Attributes |= FileAttributes.ReadOnly; if (msg.Contains("hidden")) info.Attributes |= FileAttributes.Hidden; return info; }
void DeleteDirectory(FileInformation dir, string workingDir) { List<FileInformation> files = Program.XBox.GetDirectoryList(Path.Combine(workingDir, dir.Name)); foreach (FileInformation fi in files) { lblStatus.Text = "Deleting: " + fi.Name; if (fi.Attributes == FileAttributes.Directory) DeleteDirectory(fi, Path.Combine(workingDir, dir.Name)); else Program.XBox.DeleteFile(Path.Combine(Path.Combine(workingDir, dir.Name), fi.Name)); } Program.XBox.DeleteDirectory(Path.Combine(workingDir, dir.Name)); }
void DownloadFile(FileInformation file, string workingDir, string destination) { if (!Program.XBox.Ping()) new Settings().ShowDialog(); this.Enabled = false; string xboxFilename = Path.Combine(workingDir, file.Name); if (!Program.XBox.FileExists(xboxFilename)) return; lblStatus.Text = "Downloading File: " + file.Name; Program.XBox.ReceiveFile(destination, xboxFilename); }
void DownloadDirectory(FileInformation dir, string workingDir) { throw new NotImplementedException("Can Only Download Single Files!"); if (!Program.XBox.Ping()) new Settings().ShowDialog(); string dirname = Path.GetFileName(dir.Name); if (!Program.XBox.FileExists(Path.Combine(workingDir, dirname))) Program.XBox.CreateDirectory(Path.Combine(workingDir, dirname)); foreach (string s in Directory.GetFiles(dir.Name, "*", SearchOption.TopDirectoryOnly)) { FileInformation fi = new FileInformation(); fi.Name = s; SendFile(fi, Path.Combine(workingDir, dirname)); } foreach (string s in Directory.GetDirectories(dir.Name, "*", SearchOption.TopDirectoryOnly)) { FileInformation fi = new FileInformation(); fi.Name = s; SendDirectory(fi, Path.Combine(workingDir, dirname)); } }
void SendFile(FileInformation file, string workingDir) { if (!Program.XBox.Ping()) new Settings().ShowDialog(); this.Enabled = false; string filename = Path.GetFileName(file.Name); string xboxFilename = Path.Combine(workingDir, filename); if (Program.XBox.FileExists(xboxFilename) && MessageBox.Show(filename + "\n\nWould You Like To Overwrite The Old File?", "File Already Exists.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) return; lblStatus.Text = "Sending File: " + filename; Program.XBox.SendFile(file.Name, xboxFilename); }
void listFiles_DragDrop(object sender, DragEventArgs e) { List<FileInformation> files = new List<FileInformation>(); foreach (string s in (string[])e.Data.GetData(DataFormats.FileDrop)) { FileInformation fi = new FileInformation(); fi.Name = s; if (Directory.Exists(s)) fi.Attributes = FileAttributes.Directory; files.Add(fi); } probar.Style = ProgressBarStyle.Marquee; sendFileWorker.RunWorkerAsync(files); }