Exemplo n.º 1
0
        public static byte[] readBytes(string path, bool useCloud, bool usePath)
        {
            if (useCloud)
            {
                return(ReadWrite.cloudFileRead(path));
            }
            if (usePath)
            {
                path = ReadWrite.PATH + path;
            }
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            if (!File.Exists(path))
            {
                Debug.Log("Failed to find file at: " + path);
                return(null);
            }
            FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);

            byte[] array = new byte[fileStream.Length];
            int    num   = fileStream.Read(array, 0, array.Length);

            if (num != array.Length)
            {
                Debug.LogError("Failed to read the correct file size.");
                return(null);
            }
            fileStream.Close();
            fileStream.Dispose();
            return(array);
        }
Exemplo n.º 2
0
        public static T deserializeXML <T>(string path, bool useCloud, bool usePath)
        {
            T             result        = default(T);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));

            if (useCloud)
            {
                MemoryStream memoryStream = new MemoryStream(ReadWrite.cloudFileRead(path));
                try
                {
                    result = (T)((object)xmlSerializer.Deserialize(memoryStream));
                }
                finally
                {
                    memoryStream.Close();
                    memoryStream.Dispose();
                }
                return(result);
            }
            if (usePath)
            {
                path += ReadWrite.PATH;
            }
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            if (!File.Exists(path))
            {
                Debug.Log("Failed to find file at: " + path);
                return(result);
            }
            StreamReader streamReader = new StreamReader(path);

            try
            {
                result = (T)((object)xmlSerializer.Deserialize(streamReader));
            }
            finally
            {
                streamReader.Close();
                streamReader.Dispose();
            }
            return(result);
        }