IsFileExist() 공개 정적인 메소드

public static IsFileExist ( string fullPath ) : bool
fullPath string
리턴 bool
예제 #1
0
        /// <summary>
        /// 删除没用的文件
        /// </summary>
        private void DeleteUselessFiles()
        {
            if (newmd5Table.Count == 0)
            {
                return;
            }
            List <string> deleteFiles = new List <string>();

            foreach (KeyValuePair <string, FileInfo> keyValuePair in oldmd5Table)
            {
                if (newmd5Table.ContainsKey(keyValuePair.Key))
                {
                    continue;
                }
                deleteFiles.Add(keyValuePair.Key);
                //删除沙河目录下的没用文件
                oldmd5Table.Remove(keyValuePair.Key);
            }
            foreach (string deleteFile in deleteFiles)
            {
                string filename = Platform.Path + deleteFile;
                if (FileManager.IsFileExist(filename))
                {
                    FileManager.DeleteFile(filename);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 保存md5文件 都更新成功后保存
        /// </summary>
        /// <param name="tabDictionary"></param>
        private void SaveMD5Table(Dictionary <string, FileInfo> tabDictionary)
        {
            string filename = Platform.Path + Platform.Md5FileName;

            if (FileManager.IsFileExist(filename))
            {
                FileManager.DeleteFile(filename);
            }
            string directory = Path.GetDirectoryName(filename);

            if (!string.IsNullOrEmpty(directory) && !FileManager.IsDirectoryExist(directory))
            {
                FileManager.CreateDirectory(directory);
            }
            try
            {
                using (var write = new StreamWriter(new FileStream(filename, FileMode.Create)))
                {
                    foreach (KeyValuePair <string, FileInfo> keyValuePair in tabDictionary)
                    {
                        write.WriteLine(keyValuePair.Key + "," + keyValuePair.Value.md5 + "," + keyValuePair.Value.size);
                    }
                }
            }
            catch (Exception e)
            {
                Debuger.LogError(e.Message);
            }
        }
예제 #3
0
        public Version.Version GetCurrentVersion(bool force = false)
        {
            if (currentVersion != null && !force)
            {
                return(currentVersion);
            }
            string filename = Platform.Path + Platform.AppVerFileName;

            if (FileManager.IsFileExist(filename))
            {
                try
                {
                    string version = FileManager.ReadAllText(filename);
                    if (!string.IsNullOrEmpty(version))
                    {
                        currentVersion = new Version.Version(version);
                        return(currentVersion);
                    }
                }
                catch (Exception e)
                {
                    Debuger.LogError(e.Message);
                    return(null);
                }
            }
            return(null);
        }
예제 #4
0
    public static int GetFileLength(string filePath)
    {
        if (!FileManager.IsFileExist(filePath))
        {
            return(0);
        }
        int num    = 0;
        int result = 0;

        while (true)
        {
            try
            {
                FileInfo fileInfo = new FileInfo(filePath);
                //result = (int)fileInfo.Length;
                break;
            }
            catch (Exception ex)
            {
                num++;
                if (num >= 3)
                {
                    Debug.Log("Get FileLength of " + filePath + " Error! Exception = " + ex.ToString());
                    result = 0;
                    break;
                }
            }
        }
        return(result);
    }
예제 #5
0
    public static bool DeleteFile(string filePath)
    {
        if (!FileManager.IsFileExist(filePath))
        {
            return(true);
        }
        int  num = 0;
        bool result;

        while (true)
        {
            try
            {
                File.Delete(filePath);
                result = true;
                break;
            }
            catch (Exception ex)
            {
                num++;
                if (num >= 3)
                {
                    Debug.Log("Delete File " + filePath + " Error! Exception = " + ex.ToString());
                    FileManager.s_delegateOnOperateFileFail(filePath, enFileOperation.DeleteFile);
                    result = false;
                    break;
                }
            }
        }
        return(result);
    }
예제 #6
0
 public static string GetFileMd5(string filePath)
 {
     if (!FileManager.IsFileExist(filePath))
     {
         return(string.Empty);
     }
     return(BitConverter.ToString(FileManager.s_md5Provider.ComputeHash(FileManager.ReadFile(filePath))).Replace("-", string.Empty));
 }
예제 #7
0
    public void LoadAssetBundle(string ifsExtractPath)
    {
        if (!m_isAssetBundle)
        {
            return;
        }
        if (dependency != null && dependency.m_isAssetBundle && !dependency.IsAssetBundleLoaded())
        {
            dependency.LoadAssetBundle(ifsExtractPath);
        }
        if (m_assetBundleState != enAssetBundleState.Unload)
        {
            return;
        }
        m_useAsyncLoadingData = false;
        string filePath = FileManager.CombinePath(ifsExtractPath, m_pathInIFS);

        if (FileManager.IsFileExist(filePath))
        {
            int num = 0;
            while (true)
            {
                try
                {
                    m_assetBundle = AssetBundle.LoadFromFile(filePath);
                }
                catch (Exception)
                {
                    m_assetBundle = null;
                }
                if (this.m_assetBundle != null)
                {
                    break;
                }
                num++;
                if (num >= 3)
                {
                    break;
                }
            }

            if (m_assetBundle == null)
            {
                Debug.LogError("Load AssetBundle " + filePath + " Error!!!");
            }
        }
        else
        {
            Debug.LogError("File " + filePath + " can not be found!!!");
        }
        m_assetBundleState = enAssetBundleState.Loaded;
    }
예제 #8
0
 static public int IsFileExist_s(IntPtr l)
 {
     try {
         System.String a1;
         checkType(l, 1, out a1);
         var ret = FileManager.IsFileExist(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #9
0
    bool ExportVersion(string moduleName)
    {
        int streamingHotVersion = 0;
        int cdnHotVersion       = 0;

        if (FileManager.IsFileExist(ConstValue.STREAMING_DIR_PATH + "/" + moduleName + "/" + ConstValue.VERSION_NAME))
        {
            byte[] streamingVersionBytes = FileManager.Read(ConstValue.STREAMING_DIR_PATH + "/" + moduleName + "/" + ConstValue.VERSION_NAME);
            string streamingVersionStr   = streamingVersionBytes == null ? null : ConvertExt.BytesToString(streamingVersionBytes);
            //Debug.LogError("streamingVersionStr = " + streamingVersionStr);

            JsonObject streamingVersionInfoJo = StringParser.StringToJo(streamingVersionStr, false);
            m_streamingVersion = JsonParser.JoItemToString(streamingVersionInfoJo, ConstValue.VERSION_KEY, ConstValue.VERSION);
            //Debug.LogError("streaming version: " + m_streamingVersion);
            string[] streamingVersions = m_streamingVersion.Split('.');
            streamingHotVersion = StringParser.StringToInt(streamingVersions[2]);
        }
        else
        {
            return(false);
        }

        if (FileManager.IsFileExist(m_CdnNativePath + "/" + moduleName + "/" + ConstValue.VERSION_NAME))
        {
            byte[] cdnVersionBytes = FileManager.Read(m_CdnNativePath + "/" + moduleName + "/" + ConstValue.VERSION_NAME);
            string cdnVersionStr   = cdnVersionBytes == null ? null : ConvertExt.BytesToString(cdnVersionBytes);
            //Debug.LogError("cdnVersionStr = " + cdnVersionStr);

            JsonObject cdnVersionInfoJo = StringParser.StringToJo(cdnVersionStr, false);
            m_CdnVersion = JsonParser.JoItemToString(cdnVersionInfoJo, ConstValue.VERSION_KEY, ConstValue.VERSION);
            //Debug.LogError("Cdn version: " + m_CdnVersion);
            string[] cdnVersions = m_CdnVersion.Split('.');
            cdnHotVersion = StringParser.StringToInt(cdnVersions[2]);
        }
        else
        {
            return(false);
        }

        if (streamingHotVersion <= cdnHotVersion)
        {
            return(false);
        }

        FileCopyTo(ConstValue.STREAMING_DIR_PATH + "/" + moduleName + "/" + ConstValue.VERSION_NAME,
                   m_PackagePath + "/" + moduleName + "/" + ConstValue.VERSION_NAME);

        return(true);
    }
예제 #10
0
 /// <summary>
 /// Загрузка текущих или дефолтных настроек
 /// </summary>
 /// <returns></returns>
 public GameOptions LoadOptions()
 {
     if (FileManager.IsFileExist(fullPath))
     {
         string json = FileManager.LoadFile(fullPath);
         return(JsonUtility.FromJson <GameOptions>(json));
     }
     return(new GameOptions()   //если нет предустановленых настроек то дефолтные как в unity
     {
         quality = QualitySettings.GetQualityLevel(),
         width = Screen.width,
         height = Screen.height,
         fullscreen = (int)Screen.fullScreenMode
     });
 }
예제 #11
0
    void ExportAssetBundles(string moduleName)
    {
        if (FileManager.IsFileExist(ConstValue.STREAMING_DIR_PATH + "/" + moduleName + "/" + ConstValue.FILE_LIST_NAME))
        {
            byte[] streamingFileListBytes = FileManager.Read(ConstValue.STREAMING_DIR_PATH + "/" + moduleName + "/" + ConstValue.FILE_LIST_NAME);
            string streamingFileListStr   = streamingFileListBytes == null ? null : ConvertExt.BytesToString(streamingFileListBytes);
            m_StreamingFileList = StringParser.StringToJo(streamingFileListStr, false);
        }
        else
        {
            m_StreamingFileList = new JsonObject();
        }

        if (FileManager.IsFileExist(m_CdnNativePath + "/" + moduleName + "/" + ConstValue.FILE_LIST_NAME))
        {
            byte[] cdnFileListBytes = FileManager.Read(m_CdnNativePath + "/" + moduleName + "/" + ConstValue.FILE_LIST_NAME);
            string cdnFileListStr   = cdnFileListBytes == null ? null : ConvertExt.BytesToString(cdnFileListBytes);
            m_CdnFileList = StringParser.StringToJo(cdnFileListStr, false);
        }
        else
        {
            m_CdnFileList = new JsonObject();
        }

        foreach (string fileName in m_StreamingFileList.Keys)
        {
            string     srcPath         = ConstValue.STREAMING_DIR_PATH + "/" + fileName;
            string     destPath        = m_PackagePath + "/" + fileName;
            JsonObject streamingInfoJo = JsonParser.JoItemToJo(m_StreamingFileList, fileName);
            string     streamingMd5    = JsonParser.JoItemToString(streamingInfoJo, ConstValue.FILE_LIST_MD5_KEY);
            if (m_CdnFileList.ContainsKey(fileName))
            {
                JsonObject cdnInfoJo = JsonParser.JoItemToJo(m_CdnFileList, fileName);
                string     cdnMd5    = JsonParser.JoItemToString(cdnInfoJo, ConstValue.FILE_LIST_MD5_KEY);
                if (!string.Equals(streamingMd5, cdnMd5))
                {
                    FileCopyTo(srcPath, destPath);
                }
            }
            else
            {
                FileCopyTo(srcPath, destPath);
            }
        }
        AssetDatabase.Refresh();
    }
예제 #12
0
        public static T CreateAsset <T>(string name) where T : ScriptableObject
        {
            T      asset   = ScriptableObject.CreateInstance <T>();
            string actives = AssetDatabase.GetAssetPath(Selection.activeObject);
            string path    = string.IsNullOrEmpty(actives) ? saveDir : actives;

            if (Path.GetExtension(path) != "")
            {
                path = path.Replace(Path.GetFileName(path), "");
            }
            path = path + name + exp;
            if (FileManager.IsFileExist(path))
            {
                FileManager.DeleteFile(path);
            }
            SaveAssetTo(asset, path);
            return(asset);
        }
예제 #13
0
    public static byte[] ReadFile(string filePath)
    {
        if (!FileManager.IsFileExist(filePath))
        {
            return(null);
        }
        byte[] array = null;
        int    num   = 0;

        do
        {
            try
            {
                //array = File.ReadAllBytes(filePath);
            }
            catch (Exception ex)
            {
                Debug.Log(string.Concat(new object[] {
                    "Read File ",
                    filePath,
                    " Error! Exception = ",
                    ex.ToString(),
                    ", TryCount = ",
                    num
                }));
                array = null;
            }
            if (array != null && array.Length > 0)
            {
                return(array);
            }
            num++;
        }while (num < 3);
        Debug.Log(string.Concat(new object[] {
            "Read File ",
            filePath,
            " Fail!, TryCount = ",
            num
        }));
        FileManager.s_delegateOnOperateFileFail(filePath, enFileOperation.ReadFile);
        return(null);
    }
예제 #14
0
    /// <summary>
    /// Сохранение новых настроек
    /// </summary>
    /// <param name="_quality"></param>
    /// <param name="_width"></param>
    /// <param name="_height"></param>
    /// <param name="_fullscreen"></param>
    public void SaveOptions(int _quality, int _width, int _height, int _fullscreen)
    {
        GameOptions options = new GameOptions()
        {
            quality    = _quality,
            width      = _width,
            height     = _height,
            fullscreen = _fullscreen
        };

        if (FileManager.IsFileExist(fullPath))  //сперва удаляем старый файл
        {
            FileManager.DeleteFile(fullPath);
        }

        string data = JsonUtility.ToJson(options, true);

        //FileManager.SaveFile(fullPath, fullPath, data);

        gameOptions = options;
    }
예제 #15
0
        private void ClearResourceHasUpdate()
        {
            string filename = Platform.Path + Platform.HasUpdateFileName;

            if (FileManager.IsFileExist(filename))
            {
                FileManager.DeleteFile(filename);
            }
            string directory = Path.GetDirectoryName(filename);

            if (!string.IsNullOrEmpty(directory) && !FileManager.IsDirectoryExist(directory))
            {
                FileManager.CreateDirectory(directory);
            }
            try
            {
                File.Create(filename);
            }
            catch (Exception e)
            {
                Debuger.LogError(e.Message);
            }
        }
예제 #16
0
        /// <summary>
        /// 检验本地客户端是否损坏
        /// </summary>
        /// <returns></returns>
        private bool CheckOldMd5File()
        {
            List <string> lostFiles = new List <string>();

            foreach (KeyValuePair <string, FileInfo> keyValuePair in oldmd5Table)
            {
                FileInfo fileInfo = keyValuePair.Value;
                string   filename = Platform.Path + fileInfo.fullname;
                if (FileManager.IsFileExist(filename))
                {
                    continue;
                }
                lostFiles.Add(fileInfo.fullname);
            }
            foreach (var file in lostFiles)
            {
                oldmd5Table.Remove(file);
            }
            if (lostFiles.Count > 0)
            {
                return(true);
            }
            return(false);
        }