예제 #1
0
        /// <summary>
        ///
        /// Returns [true] if there is a new update available, [false] if not, or [null] in case of error.
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <CheckUpdateResponse> CheckForUpdates()
        {
            CheckUpdateResponse checkUpdateResponse = new CheckUpdateResponse();

            try
            {
                checkUpdateResponse.CurrentVersion = Startup.CurrentAppVersion;

                string versionPage = await Http.GetAsync(Startup.ElectronManifestJObj.settings.githubVersionFileUrl.Value);

                if (versionPage.StartsWith("ERROR:"))
                {
                    checkUpdateResponse.Success      = false;
                    checkUpdateResponse.ErrorMessage = versionPage;
                    return(checkUpdateResponse);
                }
                else
                {
                    checkUpdateResponse.Success = true;
                    string line;
                    sbyte  lineNum = 0;
                    using StringReader stringReader = new StringReader(versionPage);

                    while ((line = await stringReader.ReadLineAsync()) != null)
                    {
                        lineNum++;

                        if (lineNum == 3)
                        {
                            line = line.Replace("*", String.Empty).Replace("v", String.Empty).Trim();
                            break;
                        }
                    }

                    if (checkUpdateResponse.CurrentVersion != line)
                    {
                        checkUpdateResponse.UpdateAvailable     = true;
                        checkUpdateResponse.NewAvailableVersion = line;
                    }
                    else
                    {
                        checkUpdateResponse.UpdateAvailable = false;
                    }
                }
            }
            catch (Exception e)
            {
                checkUpdateResponse.Success      = false;
                checkUpdateResponse.ErrorMessage = e.Message + "\n" + e.StackTrace;
            }

            return(checkUpdateResponse);
        }
예제 #2
0
    private void CheckUpdate()
    {
        if (Application.platform != RuntimePlatform.Android && Application.platform != RuntimePlatform.IPhonePlayer)
        {
            return;
        }

        if (Application.platform != RuntimePlatform.IPhonePlayer)
        {
            Utils.ShowMessagePanel("正在检查新版本...", messagePanel);
        }

        ResponseHandle handler = delegate(string jsonString){
            Debug.Log("GetCheckUpdate: " + jsonString);
            Utils.HideMessagePanel(messagePanel);
            //加入玩家已经游戏了,那么跳转到Gameplay Scene。否则什么都不需要坐。
            CheckUpdateResponse resp = JsonConvert.DeserializeObject <CheckUpdateResponse>(jsonString);
            if (resp.isNeedUpdate)
            {
                if (Application.platform == RuntimePlatform.Android)
                {
                    newVersion = resp.newVersion;
                    StartCoroutine(DownloadApk(resp.updateUrl));
                }
                else if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    Utils.ShowConfirmMessagePanel("发现新版本,请使用TestFlight下载最新版本!", confirmMessagePanel);
                }
            }
            else
            {
                //Utils.ShowConfirmMessagePanel("没有新版本", confirmMessagePanel);
                AutoLogin();
            }
        };

        ResponseHandle errorHandler = delegate(string error) {
            Debug.Log("errorHandler is called");
            Utils.HideMessagePanel(messagePanel);
            Utils.ShowConfirmMessagePanel("连接服务器失败,请检查你的网络", confirmMessagePanel);
        };

        var req = new {
            platform   = Utils.GetPlatform(),
            version    = Application.version,
            clientInfo = Utils.GetClientInfo(),
            userInfo   = Utils.GetUserInfo()
        };

        StartCoroutine(ServerUtils.PostRequest(ServerUtils.CheckUpdateUrl(), JsonConvert.SerializeObject(req), handler, errorHandler));
    }
예제 #3
0
        public async Task Invoke(HttpContext httpContext)
        {
            // DOT NOT AWAIT.
            _ = Task.Run(async() =>
            {
                try
                {
                    Console.WriteLine("Checking for Updates...");
                    Electron.Notification.Show(new NotificationOptions("ClassStudio", "Checking for Updates..."));

                    // TODO: Add a timeout task cancelation token.
                    CheckUpdateResponse updateCheck = await UpdateService._.CheckForUpdates();

                    if (updateCheck.Success && updateCheck.UpdateAvailable)
                    {
                        Uri updateUri = new Uri($"https://sourceforge.net/projects/class-studio/files/ClassStudio Setup {updateCheck.NewAvailableVersion}.exe/download");
                        string _title = $"ClassStudio update available";
                        string _body  = $"v{updateCheck.CurrentVersion} -> v{updateCheck.NewAvailableVersion}\nUpdate link: {updateUri}";

                        MessageBoxOptions messageBoxOptions = new MessageBoxOptions(_body)
                        {
                            Type    = MessageBoxType.info,
                            Title   = _title,
                            Buttons = new string[] { "Open Link", "Skip Update" },
                        };

                        MessageBoxResult messageBoxResult = await Electron.Dialog.ShowMessageBoxAsync(messageBoxOptions);

                        if (messageBoxResult.Response == (int)UpdateMessageBoxResult.Download)
                        {
                            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                            {
                                Process.Start(new ProcessStartInfo("cmd", $"/c start {Uri.EscapeUriString( updateUri.ToString().Replace( "&", "^&" ) )}")
                                {
                                    CreateNoWindow = true
                                });
                            }
                            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                            {
                                Process.Start("xdg-open", updateUri.ToString());
                            }
                            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                            {
                                Process.Start("open", updateUri.ToString());
                            }
                        }
                    }
                    else if (updateCheck.Success && !updateCheck.UpdateAvailable)
                    {
                        Electron.Notification.Show(new NotificationOptions("ClassStudio", "No updates available."));
                    }
                    else
                    {
                        throw new Exception("[ UPADTE ERROR ]", new Exception(JsonConvert.SerializeObject(updateCheck)));
                    }
                }
                catch (Exception e)
                {
                    Electron.Notification.Show(new NotificationOptions("ClassStudio", "An error occured during update."));

                    if (e.Message == "[ UPADTE ERROR ]")
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                    else
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            });

            await _next(httpContext);
        }