Example #1
0
        public static VersionData LoadFromFile(string _path)
        {
            using (FileStream fs = new FileStream(_path, FileMode.Open)){
                BinaryReader br = new BinaryReader(fs);

                VersionData data = new VersionData();

                data.version = br.ReadInt32();

                int length = br.ReadInt32();

                for (int i = 0; i < length; i++)
                {
                    string fileName = br.ReadString();

                    int fileVersion = br.ReadInt32();

                    data.dic.Add(fileName, fileVersion);
                }

                br.Close();

                fs.Close();

                return(data);
            }
        }
Example #2
0
        public static void SaveToFile(string _path, VersionData _data)
        {
            FileInfo fi = new FileInfo(_path);

            DirectoryInfo dir = fi.Directory;

            if (!dir.Exists)
            {
                dir.Create();
            }

            using (FileStream fs = new FileStream(_path, FileMode.OpenOrCreate)) {
                BinaryWriter bw = new BinaryWriter(fs);

                bw.Write(_data.version);

                bw.Write(_data.dic.Count);

                Dictionary <string, int> .Enumerator enumerator = _data.dic.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    KeyValuePair <string, int> pair = enumerator.Current;

                    bw.Write(pair.Key);

                    bw.Write(pair.Value);
                }

                bw.Close();

                fs.Close();
            }
        }
Example #3
0
        public void Init(int _localVersion, int _remoteVersion, Func <int, string> _fixFun, Func <string, string> _fixFun2, Action _callBack, Action <string> _setTextCallBack, Action <float> _setPercentCallBack, int _updateWarningSize, Action <string, Action> _showWarningCallBack)
        {
            if (File.Exists(Application.persistentDataPath + "/" + FILE_NAME))
            {
                data = VersionData.LoadFromFile(Application.persistentDataPath + "/" + FILE_NAME);

                if (_localVersion > data.version)                //说明残留的version.dat是老版本的  必须立即清除掉

                {
                    SuperDebug.Log("发现残留的version.dat 删除掉!");

                    data = new VersionData();

                    data.version = _localVersion;

                    VersionData.SaveToFile(Application.persistentDataPath + "/" + FILE_NAME, data);
                }
            }
            else
            {
                SuperDebug.Log("这是第一次进游戏  生成新的version.dat");

                data = new VersionData();

                data.version = _localVersion;

                VersionData.SaveToFile(Application.persistentDataPath + "/" + FILE_NAME, data);
            }

            SuperDebug.Log("客户端资源版本号:" + data.version + "  服务器资源版本号:" + _remoteVersion);

            if (data.version < _remoteVersion)
            {
                _setTextCallBack("读取热更新列表");

                Dictionary <string, UpdateFileInfo> dic = new Dictionary <string, UpdateFileInfo>();

                LoadUpdateXML(0, dic, _remoteVersion, _remoteVersion, _fixFun, _fixFun2, _callBack, _setTextCallBack, _setPercentCallBack, _updateWarningSize, _showWarningCallBack);
            }
            else
            {
                _callBack();
            }
        }
Example #4
0
        private void UpdateOver(int _remoteVersion, Action _callBack)
        {
            data.version = _remoteVersion;

            VersionData.SaveToFile(Application.persistentDataPath + "/" + FILE_NAME, data);

#if PLATFORM_PC || PLATFORM_ANDROID
            if (codeBytes != null)
            {
                SystemIO.SaveFile(Application.persistentDataPath + "/" + CODE_BYTES_NAME, codeBytes);

                codeBytes = null;

                UseFulUtil.Instance.ShowDialogOne("更新已完成,请重启游戏。", "", QuitApplication);
            }
            else
            {
                _callBack();
            }
#else
            _callBack();
#endif
        }