Exemplo n.º 1
0
        public static void Load()
        {
            var path = Assets.GetRelativeUpdatePath(appVersionFile);

            if (File.Exists(path))
            {
                var ver = new System.Version(File.ReadAllText(path));
                if (ver < new System.Version(Application.version))
                {
                    Clear();
                }
            }

            path = Assets.GetRelativeUpdatePath(versionFile);
            if (File.Exists(path))
            {
                using (var s = new StreamReader(path)) {
                    string line;
                    while ((line = s.ReadLine()) != null)
                    {
                        if (line == string.Empty)
                        {
                            continue;
                        }
                        var fields = line.Split(splitKey);
                        if (fields.Length > 1)
                        {
                            data.Add(fields [0], fields [1]);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void OnInit(AssetRequest request)
        {
            if (!string.IsNullOrEmpty(request.error))
            {
                LoadVersions(string.Empty);
                return;
            }
            var path = Assets.GetRelativeUpdatePath(versionsTxt);

            if (!File.Exists(path))
            {
                var asset = Assets.LoadAssetAsync(Assets.GetAssetBundleDataPathURL(versionsTxt), typeof(TextAsset));
                asset.completed += delegate
                {
                    if (asset.error != null)
                    {
                        LoadVersions(string.Empty);
                        return;
                    }
                    var dir = Path.GetDirectoryName(path);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    File.WriteAllText(path, asset.text);
                    LoadVersions(asset.text);
                    asset.Release();
                };
            }
            else
            {
                LoadVersions(File.ReadAllText(path));
            }
        }
Exemplo n.º 3
0
 internal static string Bundles_overrideBaseDownloadingURL(string bundleName)
 {
     if (File.Exists(Assets.GetRelativeUpdatePath(bundleName)))
     {
         return(Assets.updatePath);
     }
     return(null);
 }
Exemplo n.º 4
0
        private void LoadVersions(string text)
        {
            LoadText2Map(text, ref _versions);
            var url   = GetDownloadURL(versionsTxt);
            var asset = Assets.LoadAssetAsync(url, typeof(TextAsset));

            asset.completed += delegate
            {
                if (asset.error != null)
                {
                    OnError(asset.error);
                    return;
                }

                LoadText2Map(asset.text, ref _serverVersions);
                asset.Release();
                asset = null;

                foreach (var item in _serverVersions)
                {
                    string ver;
                    if (!_versions.TryGetValue(item.Key, out ver) || !ver.Equals(item.Value))
                    {
                        var downloader = new Download();
                        downloader.url      = GetDownloadURL(item.Key);
                        downloader.path     = item.Key;
                        downloader.version  = item.Value;
                        downloader.savePath = Assets.GetRelativeUpdatePath(item.Key);
                        _downloads.Add(downloader);
                    }
                }

                if (_downloads.Count == 0)
                {
                    Complete();
                }
                else
                {
                    var downloader = new Download();
                    downloader.url      = GetDownloadURL(Assets.platform);
                    downloader.path     = Assets.platform;
                    downloader.savePath = Assets.GetRelativeUpdatePath(Assets.platform);
                    _downloads.Add(downloader);
                    state = State.WaitDownload;
                    updateScreen.messageBox.SetActive(true);
                    updateScreen.message.text = string.Format("检查到有 {0} 个文件需要更新,点 Download 开始更新。", _downloads.Count);
                }
            };
        }
Exemplo n.º 5
0
        public static void Save()
        {
            var dir = Path.GetDirectoryName(Assets.updatePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            var path = Assets.updatePath + versionFile;

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            if (data.Count > 0)
            {
                using (var s = new StreamWriter(path)) {
                    foreach (var item in data)
                    {
                        s.WriteLine(item.Key + splitKey + item.Value);
                    }
                    s.Flush();
                    s.Close();
                }
            }

            path = Assets.GetRelativeUpdatePath(appVersionFile);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            File.WriteAllText(path, Application.version);
        }
Exemplo n.º 6
0
        private void Complete()
        {
            updateScreen.progressBar.gameObject.SetActive(false);

            Versions.Save();

            if (_downloads.Count > 0)
            {
                for (int i = 0; i < _downloads.Count; i++)
                {
                    var item = _downloads[i];
                    if (!item.isDone)
                    {
                        break;
                    }
                    else
                    {
                        if (_serverVersions.ContainsKey(item.path))
                        {
                            _versions[item.path] = _serverVersions[item.path];
                        }
                    }
                }

                StringBuilder sb = new StringBuilder();
                foreach (var item in _versions)
                {
                    sb.AppendLine(string.Format("{0}:{1}", item.Key, item.Value));
                }

                var path = Assets.GetRelativeUpdatePath(versionsTxt);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                File.WriteAllText(path, sb.ToString());
                var request = Assets.Initialize();
                request.completed = delegate(AssetRequest req)
                {
                    if (!string.IsNullOrEmpty(req.error))
                    {
                        OnError(req.error);
                    }
                    else
                    {
                        if (completed != null)
                        {
                            completed();
                        }
                    }
                };
                state = State.Completed;

                message = string.Format("{0} files has update.", _downloads.Count);
                return;
            }

            if (completed != null)
            {
                completed();
            }

            message = "nothing to update.";
            state   = State.Completed;
        }