示例#1
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 newFile = new FileInfo(newPath);                 //如果新的存在需要删除
                if (newFile.Exists)
                {
                    newFile.Delete();
                }

                FileInfo finfo = new FileInfo(oldPath);
                finfo.MoveTo(newPath);
                return(true);
            }
            return(false);
        }
示例#2
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
        }
示例#3
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
        }
示例#4
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);
            }
        }
示例#5
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("");
        }
示例#6
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));
        }
示例#7
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));
        }