/// <summary> /// Retrieves file information. /// </summary> /// <param name="fileName"></param> /// <returns></returns> public XboxFileInformation GetFileInformation(string fileName) { using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay)) { XboxCommandResponse response = _xbox.CommandSession.SendCommandStrict("getfileattributes name=\"{0}\"", fileName); if (response.Type != XboxCommandResponseType.MultiResponse) { throw new IOException("Invalid file name or file does not exist."); } string infoText = _xbox.CommandSession.ReceiveLine(); Dictionary <string, object> infoValues = infoText.ParseXboxResponseLine(); XboxFileInformation info = new XboxFileInformation(); info.FullName = fileName; info.Size = ((long)infoValues["sizehi"] << 32) | (long)infoValues["sizelo"]; info.CreationTime = DateTime.FromFileTimeUtc(((long)infoValues["createhi"] << 32) | (long)infoValues["createlo"]); info.ChangeTime = DateTime.FromFileTimeUtc(((long)infoValues["changehi"] << 32) | (long)infoValues["changelo"]); info.Attributes |= infoText.Contains("directory") ? FileAttributes.Directory : FileAttributes.Normal; info.Attributes |= infoText.Contains("readonly") ? FileAttributes.ReadOnly : 0; info.Attributes |= infoText.Contains("hidden") ? FileAttributes.Hidden : 0; return(info); } }
/// <summary> /// Deletes a directory on the Xbox. Throws an exception if the directory isn't empty, unless recursive is specified. /// Does nothing if the directory doesn't exist. /// </summary> /// <param name="path"></param> /// <param name="recursive"></param> public void DeleteDirectory(string path, bool recursive = false) { if (!_xbox.FileSystem.FileExists(path)) { return; } if (recursive) { foreach (var item in _xbox.FileSystem.GetDirectoryList(path)) { if (item.Attributes.HasFlag(FileAttributes.Directory)) { DeleteDirectory(item.FullName, true); } else { DeleteFile(item.FullName); } } } using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay)) { XboxCommandResponse response = _xbox.CommandSession.SendCommand("delete name=\"{0}\" dir", path); if (!response.Success && response.Type != XboxCommandResponseType.FileNotFound) { throw new IOException(response.Message); } } }
/// <summary> /// Deletes a file on the Xbox. Does nothing if the file doesn't exist. /// </summary> /// <param name="fileName"></param> public void DeleteFile(string fileName) { using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay)) { XboxCommandResponse response = _xbox.CommandSession.SendCommand("delete name=\"{0}\"", fileName); if (!response.Success && response.Type != XboxCommandResponseType.FileNotFound) { throw new IOException(response.Message); } } }
/// <summary> /// Creates a directory on the Xbox. Does nothing if the directory already exists. /// </summary> /// <param name="path"></param> public void CreateDirectory(string path) { using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay)) { XboxCommandResponse response = _xbox.CommandSession.SendCommand("mkdir name=\"{0}\"", path); if (!response.Success && response.Type != XboxCommandResponseType.FileAlreadyExists) { throw new IOException(response.Message); } } }
/// <summary> /// Determines if the given file or directory exists. /// </summary> /// <param name="fileName"></param> /// <returns></returns> public bool FileExists(string fileName) { using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay)) { XboxCommandResponse response = _xbox.CommandSession.SendCommand("getfileattributes name=\"{0}\"", fileName); if (response.Type == XboxCommandResponseType.MultiResponse) { _xbox.CommandSession.ReceiveLines(); } else if (response.Type != XboxCommandResponseType.FileNotFound) { throw new IOException(response.Message); } return(response.Success); } }