Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// TODO: description
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public List <XboxFileInformation> GetDirectoryList(string path)
        {
            using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay))
            {
                List <XboxFileInformation> list = new List <XboxFileInformation>();

                _xbox.CommandSession.SendCommandStrict("dirlist name=\"{0}\"", path);
                foreach (string file in _xbox.CommandSession.ReceiveLines())
                {
                    Dictionary <string, object> fileInfo = file.ParseXboxResponseLine();

                    XboxFileInformation info = new XboxFileInformation();
                    info.FullName     = Path.Combine(path, (string)fileInfo["name"]);
                    info.Size         = ((long)fileInfo["sizehi"] << 32) | (long)fileInfo["sizelo"];
                    info.CreationTime = DateTime.FromFileTimeUtc(((long)fileInfo["createhi"] << 32) | (long)fileInfo["createlo"]);
                    info.ChangeTime   = DateTime.FromFileTimeUtc(((long)fileInfo["changehi"] << 32) | (long)fileInfo["changelo"]);
                    info.Attributes  |= file.Contains("directory") ? FileAttributes.Directory : FileAttributes.Normal;
                    info.Attributes  |= file.Contains("readonly") ? FileAttributes.ReadOnly : 0;
                    info.Attributes  |= file.Contains("hidden") ? FileAttributes.Hidden : 0;
                    list.Add(info);
                }

                return(list);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Modifies file creation information. If you wish to specify a new file size, use SetFileSize instead.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="info"></param>
 public void SetFileInformation(string fileName, XboxFileInformation info)
 {
     using (_xbox.CommandSession.ExtendReceiveTimeout(ReceiveTimeoutDelay))
     {
         _xbox.CommandSession.SendCommandStrict(
             "setfileattributes name=\"{0}\" createhi={1} createlo={2} changehi={3} changelo={4} readonly={5} hidden={6}",
             fileName, (uint)(info.CreationTime.ToFileTime() >> 32),
             (uint)(info.CreationTime.ToFileTime() & uint.MaxValue),
             (uint)(info.ChangeTime.ToFileTime() >> 32),
             (uint)(info.ChangeTime.ToFileTime() & uint.MaxValue),
             info.Attributes.HasFlag(FileAttributes.ReadOnly),
             info.Attributes.HasFlag(FileAttributes.Hidden));
     }
 }