GetRealPersistentDataPath() public static method

public static GetRealPersistentDataPath ( ) : string
return string
Exemplo n.º 1
0
        public static string LoadLocalData(string fileName)
        {
            string   fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileInfo fileInfo = new FileInfo(fullPath);
            string   loadData = string.Empty;

            if (fileInfo.Exists)
            {
                using (FileStream fs = fileInfo.OpenRead())
                {
                    byte[] bytes = new byte[fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    try
                    {
                        loadData = Encoding.UTF8.GetString(CryptographHelper.Decrypt(bytes, key, iv));
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogError(ex);
                    }
                    return(loadData);
                }
            }
            return(loadData);
        }
Exemplo n.º 2
0
        public static string LoadLocalData(string fileName)
        {
            string fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);

            if (System.IO.File.Exists(fullPath))
            {
                FileStream fs = new FileStream(fullPath, FileMode.Open);
                if (fs != null && fs.Length > 0)
                {
                    byte[] bytes = new byte[fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    string loadData = string.Empty;
                    try
                    {
                        loadData = Encoding.UTF8.GetString(CryptographHelper.Decrypt(bytes, key, iv));
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogError(ex);
                    }
                    return(loadData);
                }
            }
            return("");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deletes the persistent file.
        /// </summary>
        /// <param name="fileName">File name.</param>
        public static void DeletePersistentFile(string fileName)
        {
            string path = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads the persistent file.
        /// </summary>
        /// <returns>The persistent file.</returns>
        /// <param name="fileName">File name.</param>
        public static byte[] ReadPersistentFile(string fileName)
        {
            string path = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);

            if (File.Exists(path))
            {
                return(File.ReadAllBytes(path));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Changes the name of the persistent file.
        /// </summary>
        /// <returns><c>true</c>, if persistent file name was changed, <c>false</c> otherwise.</returns>
        /// <param name="oldName">Old name.</param>
        /// <param name="newname">Newname.</param>
        public static bool ChangePersistentFileName(string oldName, string newname)
        {
            string path    = CUtils.GetRealPersistentDataPath() + "/";
            string oldPath = path + oldName;
            string newPath = path + newname;

            if (File.Exists(oldPath))
            {
                FileInfo finfo = new FileInfo(oldPath);
                finfo.MoveTo(newPath);
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 本地存储
        /// </summary>
        public static bool SaveLocalData(string fileName, string saveData)
        {
            string     fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileStream fs       = new FileStream(fullPath, FileMode.Create);

            if (fs != null)
            {
                byte[] bytes = CryptographHelper.Encrypt(Encoding.UTF8.GetBytes(saveData), key, iv);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                fs.Close();
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Delete the persistent Directory
        /// </summary>
        public static void DeletePersistentDirectory()
        {
            string        path  = CUtils.GetRealPersistentDataPath();
            DirectoryInfo dinfo = new DirectoryInfo(path);

            if (dinfo.Exists)
            {
                var      allFiles = dinfo.GetFiles("*", SearchOption.AllDirectories);
                FileInfo fino;
                for (int i = 0; i < allFiles.Length; i++)
                {
                    fino = allFiles[i];
                    fino.Delete();
                }
                ;
                dinfo.Delete(true);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 本地存储
        /// </summary>
        public static bool SaveLocalData(string fileName, string saveData)
        {
            string   fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileInfo fileInfo = new FileInfo(fullPath);

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }
            // if (!fileInfo.Exists) fileInfo.Create();
            using (var sw = fileInfo.OpenWrite())
            {
                byte[] bytes = CryptographHelper.Encrypt(Encoding.UTF8.GetBytes(saveData), key, iv);
                sw.Write(bytes, 0, bytes.Length);
                sw.Flush();
            }

            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Changes the name of the persistent file.
        /// </summary>
        /// <returns><c>true</c>, if persistent file name was changed, <c>false</c> otherwise.</returns>
        /// <param name="oldName">Old name.</param>
        /// <param name="newname">Newname.</param>
        public static bool ChangePersistentFileName(string oldName, string newname)
        {
            string path    = CUtils.GetRealPersistentDataPath();
            string oldPath = CUtils.PathCombine(path, oldName);
            string newPath = CUtils.PathCombine(path, newname);

            if (File.Exists(oldPath))
            {
                FileInfo newFile = new FileInfo(newPath);                 //如果新的存在需要删除
                if (newFile.Exists)
                {
                    newFile.Delete();
                }

                FileInfo finfo = new FileInfo(oldPath);
                finfo.MoveTo(newPath);
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Saves the file.
        /// </summary>
        /// <returns>The file.</returns>
        /// <param name="context">Context.</param>
        /// <param name="fileName">File name.</param>
        public static void SavePersistentFile(Array context, string fileName)
        {
            string path = CUtils.GetRealPersistentDataPath() + "/";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = path + fileName;

            using (StreamWriter sw = new StreamWriter(path, false))
            {
                sw.BaseStream.Write((byte[])context, 0, context.Length);
                sw.Flush();
            }

#if UNITY_EDITOR
            Debug.LogFormat("save file path={0},len={1}", path, context.Length);
#endif
        }
Exemplo n.º 11
0
        /// <summary>
        /// Saves the file.
        /// </summary>
        /// <returns>The file.</returns>
        /// <param name="context">Context.</param>
        /// <param name="fileName">File name.</param>
        public static void SavePersistentFile(Array context, string fileName)
        {
            string   path  = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileInfo finfo = new FileInfo(path);

            if (!finfo.Directory.Exists)
            {
                finfo.Directory.Create();
            }

            using (StreamWriter sw = new StreamWriter(path, false))
            {
                sw.BaseStream.Write((byte[])context, 0, context.Length);
                sw.Flush();
            }

#if UNITY_EDITOR
            Debug.LogFormat("save file path={0},len={1}", path, context.Length);
#endif
        }
Exemplo n.º 12
0
        /// <summary>
        /// Delete the persistent Directory
        /// </summary>
        public static void DeletePersistentDirectoryFiles(string relative = null)
        {
            string path = CUtils.GetRealPersistentDataPath();

            if (!string.IsNullOrEmpty(relative))
            {
                path = CUtils.PathCombine(path, relative);
            }
            DirectoryInfo dinfo = new DirectoryInfo(path);

            if (dinfo.Exists)
            {
                var      allFiles = dinfo.GetFiles("*", SearchOption.AllDirectories);
                FileInfo fino;
                for (int i = 0; i < allFiles.Length; i++)
                {
                    fino = allFiles[i];
                    fino.Delete();
                }
                ;
                // dinfo.Delete(true);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// the Persistents  file is Exists.
        /// </summary>
        /// <returns><c>true</c>, if file was persistented, <c>false</c> otherwise.</returns>
        /// <param name="abpath">Abpath.</param>
        public static bool PersistentFileExists(string abpath)
        {
            string path = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), abpath);

            return(File.Exists(path));
        }
Exemplo n.º 14
0
        /// <summary>
        /// the Persistents  file is Exists.
        /// </summary>
        /// <returns><c>true</c>, if file was persistented, <c>false</c> otherwise.</returns>
        /// <param name="abpath">Abpath.</param>
        public static bool PersistentFileExists(string abpath)
        {
            string path = CUtils.GetRealPersistentDataPath() + "/" + abpath;

            return(File.Exists(path));
        }