Example #1
0
        private void PerformAutoUpdateInstall(string patchFolder, IProgressMonitor progressMonitor)
        {
            logger.Info("Prepare updates");

            progressMonitor.StatusText = Resources.Module_Updater_UI_Log_PrepareUpdates;
            progressMonitor.Progress   = 0d;

            var tmp = System.IO.Path.Combine(patchFolder, "Gobchat");

            if (System.IO.Directory.Exists(tmp))
            {
                patchFolder = tmp;
            }

            var manager = NAppUpdate.Framework.UpdateManager.Instance;

            manager.UpdateSource                = new NAULocalFileUpdateSource(patchFolder);
            manager.UpdateFeedReader            = new NAULocalFileFeedReader();
            manager.Config.UpdateExecutableName = System.AppDomain.CurrentDomain.FriendlyName;

            manager.ReinstateIfRestarted();
            manager.CheckForUpdates();

            progressMonitor.Log(StringFormat.Format(Resources.Module_Updater_UI_Log_UpdateCount, manager.UpdatesAvailable));

            if (manager.UpdatesAvailable > 0)
            {
                manager.PrepareUpdates();
            }

            progressMonitor.StatusText = Resources.Module_Updater_UI_Log_Done;
            progressMonitor.Progress   = 1d;

            logger.Info($"{manager.UpdatesAvailable} updates prepared.");
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="progressMonitor"></param>
        /// <returns></returns>
        /// <exception cref="DownloadFailedException"></exception>
        public Result Download(IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
            {
                throw new ArgumentNullException(nameof(progressMonitor));
            }

            if (IsFileAlreadyDownloaded())
            {
                return(Result.Skipped);
            }

            try
            {
                Directory.CreateDirectory(OutputFolder);
                var result = DownloadHelper.DownloadFileFromGithub(downloadUrl: URL, destinationFile: FilePath, progressMonitor);
                switch (result)
                {
                case DownloadHelper.DownloadResult.Canceled:
                    DeleteFile(progressMonitor);
                    return(Result.Canceled);
                }
            }
            catch (DownloadFailedException ex)
            {
                progressMonitor.Log(StringFormat.Format(Resources.GeneralErrorOccured, ex.Message));
                DeleteFile(progressMonitor);
                throw;
            }

            return(Result.Completed);
        }
Example #3
0
        //TODO exception handling
        public string ExtractCef(IProgressMonitor progressMonitor)
        {
            if (IsCefAvailable())
            {
                return(_cefLibFolder); //Done
            }
            Directory.CreateDirectory(_cefLibFolder);
            var unpackingResults = ArchiveUnpackerHelper.ExtractArchive(_cefPatchArchive, _cefLibFolder, progressMonitor);

            switch (unpackingResults)
            {
            case ArchiveUnpackerHelper.ExtractionResult.Complete:
                progressMonitor.Log(Resources.Module_Cef_Installer_Unpack_Complete);
                File.Delete(_cefPatchArchive);
                break;

            case ArchiveUnpackerHelper.ExtractionResult.Canceled:
                progressMonitor.Log(StringFormat.Format(Resources.Module_Cef_Installer_Unpack_DeleteIncomplete, _cefLibFolder));
                Directory.Delete(_cefLibFolder, true);
                throw new OperationCanceledException("Unpacking canceled");
            }

            if (!IsCefAvailable())
            {
                //TODO throw exception
                throw new DirectoryNotFoundException(_cefLibFolder);
            }

            return(_cefLibFolder);
        }
Example #4
0
        public string DownloadCef(IProgressMonitor progressMonitor)
        {
            if (!IsCefArchiveAvailable())
            {
                try
                {
                    Directory.CreateDirectory(_cefPatchFolder);
                    var result = DownloadHelper.DownloadFileFromGithub(_cefDownloadUrl, _cefPatchArchive, progressMonitor);
                    switch (result)
                    {
                    case DownloadHelper.DownloadResult.Canceled:
                        progressMonitor.Log(StringFormat.Format(Resources.Module_Cef_Installer_Download_DeleteIncomplete, _cefPatchArchive));
                        File.Delete(_cefPatchArchive);
                        throw new OperationCanceledException("Download canceled");
                    }
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception e) //TODO not good
                {
                    progressMonitor.Log(StringFormat.Format(Resources.GeneralErrorOccured, e.Message));
                    File.Delete(_cefPatchArchive);
                    throw;
                }

                if (!IsCefArchiveAvailable())
                {
                    throw new DirectoryNotFoundException(_cefPatchArchive);
                }
            }

            return(_cefPatchArchive);
        }
Example #5
0
        /// <summary>
        /// 获取缓存的变体资源包名称
        /// </summary>
        private string GetCachedVariantBundleName(string bundleName, string variant)
        {
            if (_cacheNames.ContainsKey(bundleName))
            {
                return(_cacheNames[bundleName]);
            }

            // 获取变体资源格式
            string variantBundleName = bundleName;

            if (_variantRuleCollection.ContainsKey(variant))
            {
                string extension = _variantRuleCollection[variant];
                if (extension == VariantRule.DefaultTag)
                {
                    extension = PatchDefine.AssetBundleDefaultVariant;
                }
                string filePathWithoutExtension = bundleName.Remove(bundleName.LastIndexOf("."));
                variantBundleName = StringFormat.Format("{0}.{1}", filePathWithoutExtension, extension);
            }
            else
            {
                MotionLog.Warning($"Not found variant in rules : {variant}");
            }

            // 添加到缓存列表
            _cacheNames.Add(bundleName, variantBundleName);
            return(variantBundleName);
        }
Example #6
0
        /// <summary>
        /// 尝试获取注册的变体资源清单路径
        /// </summary>
        /// <returns>如果没有注册,返回原路径</returns>
        public string TryGetVariantManifestPath(string manifestPath)
        {
            // 如果不是变体资源
            if (manifestPath.EndsWith(PatchDefine.AssetBundleDefaultVariantWithPoint))
            {
                return(manifestPath);
            }

            if (_cacheFiles.ContainsKey(manifestPath))
            {
                return(_cacheFiles[manifestPath]);
            }

            // 获取变体资源格式
            string targetManifestPath = manifestPath;
            string fileExtension      = Path.GetExtension(manifestPath);        //注意:包含点前缀

            if (_variantRuleCollection.ContainsKey(fileExtension))
            {
                string targetExtension          = _variantRuleCollection[fileExtension];
                string filePathWithoutExtension = manifestPath.Remove(manifestPath.LastIndexOf("."));
                targetManifestPath = StringFormat.Format("{0}{1}", filePathWithoutExtension, targetExtension);
            }

            // 添加到缓存列表
            _cacheFiles.Add(manifestPath, targetManifestPath);
            return(targetManifestPath);
        }
Example #7
0
 public void TestMethod1()
 {
     Assert.AreEqual("a,b,c", StringFormat.Format("{0},{1},{2}", "a", "b", "c"));
     Assert.AreEqual("a,b,null", StringFormat.Format("{0},{1},{2}", "a", "b"));
     Assert.AreEqual("a,b,c", StringFormat.Format("{0},{1},{2}", "a", "b", "c", "d"));
     Assert.AreEqual("{0},b,c", StringFormat.Format("{{0}},{1},{2}", "a", "b", "c"));
 }
Example #8
0
        private void ConfigManager_Update(IConfigManager sender, ProfilePropertyChangedCollectionEventArgs evt)
        {
            var keyString = sender.GetProperty <string>(_configKey);
            //var keyString = sender.GetProperty<string>($"{_configKey}.key");
            var keyActive = true; //sender.GetProperty<bool>($"{_configKey}.active");
            var _newKeys  = StringToKeys(keyString);

            try
            {
                if (_newKeys != _keys)
                {
                    _hotkeyManager.RemoveKey(_hotkeyId, _keys);
                    _keys = _newKeys;
                    if (_keys != Keys.None)
                    {
                        _hotkeyManager.AddKey(_hotkeyId, _newKeys);
                    }
                }

                //  if (_keys != Keys.None)
                _hotkeyManager.ToggleHotkey(_hotkeyId, keyActive);
            }
            catch (HotkeyRegisterException ex1)
            {
                logger.Fatal(ex1, $"Invalid Hotkey for {_hotkeyId}");
                _chatManager.EnqueueMessage(Core.Chat.SystemMessageType.Error, StringFormat.Format(Resources.Module_Hotkey_ConfigHotkeyUpdater_InvalidHotkey, _hotkeyName, ex1.Message));
            }
            catch (Exception ex2)
            {
                logger.Fatal(ex2, $"Unknown Hotkey exception {_hotkeyId}");
                _chatManager.EnqueueMessage(Core.Chat.SystemMessageType.Error, StringFormat.Format(Resources.Module_Hotkey_ConfigHotkeyUpdater_InvalidHotkey, _hotkeyName, ex2.Message));
            }
        }
Example #9
0
        /// <summary>
        /// 尝试获取注册的变体资源清单路径
        /// </summary>
        /// <returns>如果没有注册,返回原路径</returns>
        public string TryGetVariantManifestPath(string manifestPath, string variant)
        {
            if (_cacheFiles.ContainsKey(manifestPath))
            {
                return(_cacheFiles[manifestPath]);
            }

            // 获取变体资源格式
            string variantManifestPath = manifestPath;

            if (_variantRuleCollection.ContainsKey(variant))
            {
                string extension = _variantRuleCollection[variant];
                if (extension == VariantRule.DefaultTag)
                {
                    extension = PatchDefine.AssetBundleDefaultVariant;
                }
                string filePathWithoutExtension = manifestPath.Remove(manifestPath.LastIndexOf("."));
                variantManifestPath = StringFormat.Format("{0}.{1}", filePathWithoutExtension, extension);
            }

            // 添加到缓存列表
            _cacheFiles.Add(manifestPath, variantManifestPath);
            return(variantManifestPath);
        }
Example #10
0
        private (bool, string) PerformAutoUpdateDownload(IUpdateDescription update, string targetFolder, IProgressMonitor progressMonitor)
        {
            var fileDownloader = new GitHubFileDownloader(update.DirectDownloadUrl, targetFolder);

            fileDownloader.FileName = $"gobchat-{update.Version.Major}.{update.Version.Minor}.{update.Version.Patch}-{update.Version.PreRelease}.zip";

            try
            {
                var downloadResult = fileDownloader.Download(progressMonitor);
                switch (downloadResult)
                {
                case GitHubFileDownloader.Result.Canceled:
                    return(false, null);
                }
            }
            catch (DownloadFailedException ex)
            {
                logger.Error(ex);

                System.Windows.Forms.MessageBox.Show(
                    StringFormat.Format(Resources.Module_Updater_Dialog_DownloadFailed_Text, ex.ToString()),
                    Resources.Module_Updater_Dialog_DownloadFailed_Title,
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error
                    );

                return(false, null);
            }

            return(true, fileDownloader.FilePath);
        }
Example #11
0
        public void Initialize(ApplicationStartupHandler handler, IDIContext container)
        {
            if (handler == null)
            {
                throw new System.ArgumentNullException(nameof(handler));
            }

            DeleteOldPatchData();

            var configManager = container.Resolve <IConfigManager>();
            var doUpdate      = configManager.GetProperty <bool>("behaviour.appUpdate.checkOnline");

            if (!doUpdate)
            {
                return;
            }

            var allowBetaUpdates = configManager.GetProperty <bool>("behaviour.appUpdate.acceptBeta");

            var update = GetUpdate(GobchatContext.ApplicationVersion, allowBetaUpdates);

            if (update == null)
            {
                return;
            }

            var userRequest = AskUser(update);

            if (userRequest == UpdateFormDialog.UpdateType.Skip)
            {
                return;
            }

            if (userRequest == UpdateFormDialog.UpdateType.Auto)
            {
                var needRestart = PerformAutoUpdate(container, update);
                if (needRestart)
                {
                    handler.StopStartup = true;
                }
            }

            if (userRequest == UpdateFormDialog.UpdateType.Manual)
            {
                var dialogText   = StringFormat.Format(Resources.Module_Updater_Dialog_ManualInstall_Text, update.Version);
                var dialogResult = System.Windows.Forms.MessageBox.Show(dialogText, Resources.Module_Updater_Dialog_ManualInstall_Title, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information);

                //TODO improve - a lot

                if (System.Windows.Forms.DialogResult.Yes == dialogResult)
                {
                    System.Diagnostics.Process downloadProcess = System.Diagnostics.Process.Start(update.PageUrl);
                    handler.StopStartup = true;
                }
            }
        }
Example #12
0
        /// <summary>
        /// 获取基于沙盒文件夹的加载路径
        /// </summary>
        public static string MakePersistentLoadPath(string path)
        {
#if UNITY_EDITOR
            // 注意:为了方便调试查看,编辑器下把存储目录放到项目里
            string projectPath = GetDirectory(UnityEngine.Application.dataPath);
            return(StringFormat.Format("{0}/Sandbox/{1}", projectPath, path));
#else
            return(StringFormat.Format("{0}/Sandbox/{1}", UnityEngine.Application.persistentDataPath, path));
#endif
        }
Example #13
0
 private UpdateFormDialog.UpdateType AskUser(IUpdateDescription update)
 {
     using (var notes = new UpdateFormDialog())
     {
         notes.UpdateHeadText = StringFormat.Format(notes.UpdateHeadText, update.Version, GobchatContext.ApplicationVersion);
         notes.UpdateNotes    = update.PatchNotes;
         notes.ShowDialog();
         return(notes.UpdateRequest);
     }
 }
        /// <summary>
        /// 获取基于沙盒文件夹的加载路径
        /// </summary>
        public static string MakePersistentLoadPath(string assetPath)
        {
#if UNITY_EDITOR
            // 注意:为了方便调试查看,编辑器下把存储目录放到项目里
            string projectPath = Path.GetDirectoryName(Application.dataPath);
            projectPath = GetRegularPath(projectPath);
            return(StringFormat.Format("{0}/Sandbox/{1}", projectPath, assetPath));
#else
            return(StringFormat.Format("{0}/Sandbox/{1}", Application.persistentDataPath, assetPath));
#endif
        }
Example #15
0
        /// <summary>
        /// 获取网络资源加载路径
        /// </summary>
        public static string ConvertToWWWPath(string path)
        {
            // 注意:WWW加载方式,必须要在路径前面加file://
#if UNITY_EDITOR
            return(StringFormat.Format("file:///{0}", path));
#elif UNITY_IPHONE
            return(StringFormat.Format("file://{0}", path));
#elif UNITY_ANDROID
            return(path);
#elif UNITY_STANDALONE
            return(StringFormat.Format("file:///{0}", path));
#endif
        }
        public static string ConvertResourcePathToManifestPath(string path)
        {
            if (CachedManifestRootPath == null)
            {
                if (string.IsNullOrEmpty(AssetSystem.AssetRootPath))
                {
                    throw new System.Exception("Asset system root path is null or empty.");
                }
                CachedManifestRootPath = AssetSystem.AssetRootPath.ToLower();
            }

            path = path.ToLower();             //转换为小写形式
            return(StringFormat.Format("{0}/{1}{2}", CachedManifestRootPath, path, PatchDefine.StrBundleSuffixName));
        }
        string IBundleServices.ConvertLocationToManifestPath(string location, string variant)
        {
            if (_cachedLocationRoot == null)
            {
                if (string.IsNullOrEmpty(AssetSystem.LocationRoot))
                {
                    throw new System.Exception($"{nameof(AssetSystem.LocationRoot)} is null or empty.");
                }
                _cachedLocationRoot = AssetSystem.LocationRoot.ToLower();
            }

            if (string.IsNullOrEmpty(variant))
            {
                throw new System.Exception($"Variant is null or empty: {location}");
            }

            return(StringFormat.Format("{0}/{1}.{2}", _cachedLocationRoot, location.ToLower(), variant));
        }
Example #18
0
        /// <summary>
        /// 将资源定位地址转换为清单路径
        /// </summary>
        public static string ConvertLocationToManifestPath(string location, string variant)
        {
            // 注意:在编辑器模式下,加载路径是大小写敏感的
            if (_cachedLowerLocationRoot == null)
            {
                if (string.IsNullOrEmpty(AssetSystem.LocationRoot))
                {
                    throw new System.Exception($"{nameof(AssetSystem.LocationRoot)} is null or empty.");
                }
                _cachedLowerLocationRoot = AssetSystem.LocationRoot.ToLower();
            }

            if (string.IsNullOrEmpty(variant))
            {
                throw new System.Exception($"Variant is null or empty: {location}");
            }

            return(StringFormat.Format("{0}/{1}.{2}", _cachedLowerLocationRoot, location.ToLower(), variant.ToLower()));
        }
Example #19
0
        private (bool, string) PerformAutoUpdateExtraction(string archivePath, string patchFolder, IProgressMonitor progressMonitor)
        {
            var outputFolder = System.IO.Path.Combine(patchFolder, TempPatchFolder);
            var unpacker     = new ArchiveUnpacker(archivePath, outputFolder);

#if DEBUG
            unpacker.DeleteArchiveOnCompletion = false;
#else
            unpacker.DeleteArchiveOnCompletion = true;
#endif
            unpacker.DeleteOutputFolderOnFail = true;

            try
            {
                var result = unpacker.Extract(progressMonitor);
                switch (result)
                {
                case ArchiveUnpacker.Result.Canceled:
                    return(false, null);
                }
            }
            catch (ExtractionFailedException ex)
            {
                logger.Error(ex);

                System.Windows.Forms.MessageBox.Show(
                    StringFormat.Format(Resources.Module_Updater_Dialog_ExtractionFailed_Text, ex.ToString()),
                    Resources.Module_Updater_Dialog_ExtractionFailed_Title,
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error
                    );

                return(false, null);
            }

            return(true, outputFolder);
        }
Example #20
0
 private void DeleteFile(IProgressMonitor progressMonitor)
 {
     progressMonitor.Log(StringFormat.Format(Resources.Module_Updater_UI_Log_DeleteFile, FilePath));
     File.Delete(FilePath);
 }
Example #21
0
 /// <summary>
 /// 获取基于流文件夹的加载路径
 /// </summary>
 public static string MakeStreamingLoadPath(string path)
 {
     return(StringFormat.Format("{0}/{1}", UnityEngine.Application.streamingAssetsPath, path));
 }
 /// <summary>
 /// 获取基于流文件夹的加载路径
 /// </summary>
 public static string MakeStreamingLoadPath(string assetPath)
 {
     return(StringFormat.Format("{0}/{1}", Application.streamingAssetsPath, assetPath));
 }
        public void Initialize(ApplicationStartupHandler handler, IDIContext container)
        {
            var uiSynchronizer = container.Resolve <IUISynchronizer>();
            ProgressDisplayForm progressDisplay = null;

            var cefFolder     = Path.Combine(GobchatContext.ApplicationLocation, "libs", "cef");
            var patcherFolder = Path.Combine(GobchatContext.ApplicationLocation, "patch");
            var installer     = new CefInstaller(cefFolder, patcherFolder);

            if (installer.IsCefAvailable())
            {
                return;
            }

            //TODO message dialog
            {
                logger.Info("CEF missing");
                var dialogResult = MessageBox.Show(
                    Resources.Module_Cef_Dialog_CefMissing_Text,
                    "Gobchat",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning
                    );

                if (dialogResult != DialogResult.Yes)
                {
                    handler.StopStartup = true;
                    return;
                }
            }

            try
            {
                uiSynchronizer.RunSync(() =>
                {
                    progressDisplay = new ProgressDisplayForm();
                    progressDisplay.Show();
                });

                using (var progressMonitor = new ProgressMonitorAdapter(progressDisplay))
                {
                    try
                    {
                        installer.DownloadCef(progressMonitor);
                    }
                    catch (Exception e)
                    {
                        logger.Log(LogLevel.Fatal, e, () => "CEF download failed");
                        throw;
                    }
                    try
                    {
                        installer.ExtractCef(progressMonitor);
                    }
                    catch (Exception e)
                    {
                        logger.Log(LogLevel.Fatal, e, () => "CEF extraction failed");
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                logger.Fatal("CEF installation failed");
                logger.Fatal(e);

                MessageBox.Show(
                    StringFormat.Format(Resources.Module_Cef_Dialog_InstallFailed_Text, e.Message),
                    Resources.Module_Cef_Dialog_InstallFailed_Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                handler.StopStartup = true;
            }
            finally
            {
                uiSynchronizer.RunSync(() => progressDisplay.Dispose());
            }
        }