Пример #1
0
        private void btPackage_Click(object sender, EventArgs e)
        {
            string src  = tbPath.Text;
            string file = tbName.Text + "-" + tbVersion.Text.Replace('.', '-') + ".udp";
            string dst  = DirTool.Combine(DirTool.GetFilePath(tbPath.Text), file);

            if (FilePackageTool.Pack(src, dst) > 0 && File.Exists(dst))
            {
                string md5Code = FileTool.GetMD5(dst);
                //设置更新模型,14个属性
                AppUpdateInfo aui = new AppUpdateInfo()
                {
                    Name         = tbName.Text,
                    Author       = tbAuthor.Text,
                    Desc         = tbDesc.Text,
                    Version      = tbVersion.Text,
                    ReleasePath  = tbReleasePath.Text,
                    Necessary    = cbNecessary.Checked,
                    DateTime     = DateTime.Now,
                    DownloadMode = rbHttpMode.Checked ? 0 : 1,
                    HttpUrl      = tbHttpUrl.Text,
                    FtpIp        = tbFtpIp.Text,
                    FtpAccount   = tbFtpAccount.Text,
                    FtpPassword  = tbFtpPassword.Text,
                    FtpFile      = tbFtpFile.Text,
                    Md5          = md5Code,
                };
                string auiJson = JsonTool.ToStr(aui);
                TxtTool.Create(dst + ".txt", auiJson);
            }
        }
        public AppUpdateInfo GetUpdateInfo()
        {
            AppUpdateInfo TempUpInfo    = null;
            string        UpdateFileDir = System.IO.Path.Combine(_configuration["StaticFileDir"], "UpdateFiles");

            if (!System.IO.Directory.Exists(UpdateFileDir))
            {
                return(new AppUpdateInfo());
            }
            string UpdateFileName = System.IO.Path.Combine(UpdateFileDir, "UpdateInfo.json");

            if (!System.IO.File.Exists(UpdateFileName))
            {
                return(new AppUpdateInfo());
            }
            string UpdateInfoStr = System.IO.File.ReadAllText(UpdateFileName).Replace("\r\n", "", System.StringComparison.Ordinal);

            if (string.IsNullOrWhiteSpace(UpdateInfoStr))
            {
                return(new AppUpdateInfo());
            }
            TempUpInfo = JsonConvert.DeserializeObject <AppUpdateInfo>(UpdateInfoStr);
            if (TempUpInfo == null)
            {
                return(new AppUpdateInfo());
            }
            return(TempUpInfo);
        }
        public static bool StartUpdater()
        {
            bool res;

            try
            {
                updateInfo = new AppUpdateInfo();

                System.Diagnostics.Process.Start(
                    System.Windows.Forms.Application.StartupPath +
                    System.IO.Path.DirectorySeparatorChar +
                    UpdaterProcessName);

                timer          = new System.Timers.Timer(10000);
                timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
                timer.Start();

                res = true;
            }
            catch (Exception ex)
            {
                try
                {
                    DomainModel.Application.Status.Update(
                        StatusController.Abstract.StatusTypes.Error,
                        "",
                        ex.Message);
                }
                catch { }

                res = false;
            }

            return(res);
        }
Пример #4
0
        private void InitiateRequest(AppUpdateRequestImpl request, AppUpdateInfo appUpdateInfo,
                                     AppUpdateOptions appUpdateOptions)
        {
            if (appUpdateInfo.UpdateAvailability == UpdateAvailability.DeveloperTriggeredUpdateInProgress)
            {
                // If an update is already in progress, it would skip user confirmation dialog and
                // the ActivityResult for user confirmation should be set to ResultOk.
                request.SetUpdateActivityResult(ActivityResult.ResultOk);
            }

            if (request.IsDone && appUpdateOptions.AppUpdateType == AppUpdateType.Flexible)
            {
                request.OnUpdateDownloaded();
            }
            else
            {
                var requestFlowTask = _appUpdateManagerPlayCore.StartUpdateFlow(appUpdateInfo, appUpdateOptions);

                requestFlowTask.RegisterOnSuccessCallback(resultCode =>
                {
                    // Set user confirmation dialog result for the update request.
                    request.SetUpdateActivityResult(resultCode);
                    requestFlowTask.Dispose();
                });

                requestFlowTask.RegisterOnFailureCallback((reason, errorCode) =>
                {
                    Debug.LogErrorFormat("Update flow request failed: {0}", errorCode);
                    request.OnErrorOccurred(AppUpdatePlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                    requestFlowTask.Dispose();
                });
            }
        }
Пример #5
0
        /// <summary>
        /// 判断需要下载的升级文件是否已经全部正确下载。
        /// </summary>
        /// <param name="appUpdateInfo"></param>
        /// <returns></returns>
        private bool CheckDownResult(AppUpdateInfo appUpdateInfo)
        {
            //合成目录
            string        tempFileDir   = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UpdateApp");
            DirectoryInfo directoryInfo = new DirectoryInfo(tempFileDir);

            if (!directoryInfo.Exists)
            {
                return(false);
            }

            FileInfo[] DFiles = directoryInfo.GetFiles();
            if (DFiles == null || appUpdateInfo.UpdateFiles.Count != DFiles.Count())
            {
                return(false);
            }

            foreach (FileInfo item in DFiles)
            {
                if (!appUpdateInfo.UpdateFiles.Contains(item.Name) || item.Length < 1)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #6
0
        public object CheckUpdate([FromForm] AppInfoInput model)
        {
            var path       = DotNet.Configuration.Config.GetSection("UpdatePath").Value ?? @"wwwroot\files";
            var appVersion = int.Parse(DotNet.Configuration.Config.GetSection("AppVersion").Value ?? "2310000");

            if (model.AppVersion < appVersion)
            {
                var appPath = System.IO.Path.Combine(path, model.AppId.ToString(), appVersion.ToString());
                if (System.IO.Directory.Exists(appPath))
                {
                    var           cache     = System.IO.Path.Combine(appPath, "cache.cache");
                    AppUpdateInfo appUpdate = new AppUpdateInfo();
                    if (System.IO.File.Exists(cache))
                    {
                        appUpdate = System.IO.File.ReadAllText(cache).JsonToObject <AppUpdateInfo>();
                        return(new DotNet.Result <AppUpdateInfo>()
                        {
                            Code = 200,
                            Success = true,
                            Message = string.Empty,
                            Data = appUpdate
                        });
                    }
                    List <FileInfo> list  = new List <FileInfo>();
                    var             files = System.IO.Directory.GetFiles(appPath, "*", System.IO.SearchOption.AllDirectories);
                    appUpdate = new AppUpdateInfo()
                    {
                        AppVersion = appVersion, Description = string.Empty, Id = 1, UpdateFlag = 1, UpdateTime = DateTime.Now
                    };
                    foreach (var file in files)
                    {
                        var fileInfo = new System.IO.FileInfo(file);
                        list.Add(new FileInfo
                        {
                            FileName = fileInfo.Name,
                            MD5      = GetMD5(file),
                            Path     = file.Remove(0, appPath.Length + 1),
                            Size     = fileInfo.Length,
                            Url      = $"/files{file.Remove(0, path.Length)}"
                        });;
                    }
                    appUpdate.List = list.ToArray();
                    System.IO.File.WriteAllText(cache, appUpdate.ToJson());
                    return(new DotNet.Result <AppUpdateInfo>()
                    {
                        Code = 200,
                        Success = true,
                        Message = string.Empty,
                        Data = appUpdate
                    });
                }
            }
            return(new DotNet.Result()
            {
                Code = 0, Success = false, Message = "没有要更新的"
            });
        }
Пример #7
0
        /// <summary>
        /// Starts the desired update flow indicated by <param name="appUpdateOptions"> asynchronously.
        /// </summary>
        /// <param name="appUpdateInfo">The on success result of <see cref="GetAppUpdateInfo"/>.</param>
        /// <param name="appUpdateOptions"><see cref="AppUpdateOptions"/> contains update type options.</param>
        /// <returns>
        /// A <see cref="PlayCoreTask<int>"/> which gives an int result
        /// once the dialog has been accepted, denied or closed.
        /// A successful task result contains one of the following values:
        /// <ul>
        ///   <li><see cref="ActivityResult.ResultOk"/> -1 if the user accepted.</li>
        ///   <li><see cref="ActivityResult.ResultCancelled"/> 0 if the user denied or the dialog has been closed in
        ///       any other way (e.g. backpress).</li>
        ///   <li><see cref="ActivityResult.ResultFailed"/> 1 if the activity created to achieve has failed.</li>
        /// </ul>
        /// </returns>
        public PlayCoreTask <int> StartUpdateFlow(AppUpdateInfo appUpdateInfo, AppUpdateOptions appUpdateOptions)
        {
            var javaTask =
                _javaAppUpdateManager.Call <AndroidJavaObject>("startUpdateFlow",
                                                               appUpdateInfo.GetJavaUpdateInfo(), UnityPlayerHelper.GetCurrentActivity(),
                                                               appUpdateOptions.GetJavaAppUpdateOptions());

            return(new PlayCoreTask <int>(javaTask));
        }
Пример #8
0
 public IActionResult Update(string apiKey, [FromBody] AppUpdateInfo info)
 {
     return(_db.Try(_db => {
         _db.GetCollection <AppInfo>("apps")
         .UpdateOne(x => x.ApiKey == apiKey,
                    Builders <AppInfo> .Update.Combine(
                        Builders <AppInfo> .Update.Set(x => x.Port, info.Port),
                        Builders <AppInfo> .Update.Set(x => x.ServerNames, info.ServerNames)
                        ));
         return _db.GetCollection <AppInfo>("apps").AsQueryable().FirstOrDefault(x => x.ApiKey == apiKey);
     }).Bind <AppInfo>(app => {
         _nginxService.RefreshConfig();
         _processManager.Restart(app);
         return app;
     })
            .Right(x => Ok(x) as IActionResult)
            .Left(x => BadRequest(x.Message) as IActionResult));
 }
Пример #9
0
        /// <summary>
        /// Creates an <see cref="AppUpdateRequest"/> that can be used to monitor the update progress and start the
        /// desired update flow indicated by <see cref="appUpdateOptions"/>.
        /// </summary>
        /// <param name="appUpdateInfo">The on success result of <see cref="GetAppUpdateInfo"/>.</param>
        /// <param name="appUpdateOptions"><see cref="AppUpdateOptions"/> contains update type options.</param>
        /// <returns>
        /// A <see cref="AppUpdateRequest"/> which can be used to monitor the asynchronous request of an update flow.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Throws if any of the the provided parameters are null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Throws if there is already an <see cref="AppUpdateRequest"/> in progress.
        /// </exception>
        public AppUpdateRequest StartUpdateInternal(AppUpdateInfo appUpdateInfo, AppUpdateOptions appUpdateOptions)
        {
            if (appUpdateInfo == null)
            {
                throw new ArgumentNullException("appUpdateInfo");
            }

            if (appUpdateOptions == null)
            {
                throw new ArgumentNullException("appUpdateOptions");
            }

            if (_appUpdateRequest != null)
            {
                throw new InvalidOperationException(
                          "Another update flow is already in progress.");
            }

            _appUpdateRequest = new AppUpdateRequestImpl();

            if (appUpdateInfo.UpdateAvailability == UpdateAvailability.UpdateNotAvailable)
            {
                _appUpdateRequest.OnErrorOccurred(AppUpdateErrorCode.ErrorUpdateUnavailable);
                return(_appUpdateRequest);
            }

            if (!appUpdateInfo.IsUpdateTypeAllowed(appUpdateOptions))
            {
                _appUpdateRequest.OnErrorOccurred(AppUpdateErrorCode.ErrorUpdateNotAllowed);
                return(_appUpdateRequest);
            }

            _appUpdateRequest.Completed += (req) => { _appUpdateRequest = null; };
            InitiateRequest(_appUpdateRequest, appUpdateInfo, appUpdateOptions);
            return(_appUpdateRequest);
        }
Пример #10
0
        /// <summary>
        /// 检查并升级系统
        /// </summary>
        /// <returns></returns>
        private async Task CheckAppUpdateAsync()
        {
            _UpdateAppTimer.Stop();
            //1.检查是否需要更新。
            List <string> NeedUpdateFiles = new List <string>();
            //读取服务器端本系统程序的信息。
            AppUpdateInfo UpdateInfo = await DataFileUpdateAppRepository.GetAppUpdateInfo();

            if (UpdateInfo == null)
            {
                this.notifyIcon.ShowBalloonTip(1000, "错误", "获取程序升级信息时出错...", ToolTipIcon.Error);
                _UpdateAppTimer.Start();
                return;
            }
            //如果服务器程序升级信息比本地记录的晚,则升级之。
            if (UpdateInfo.UpdateDate > AppSet.LocalSetting.AppUpDateTime)
            {
                NeedUpdateFiles = UpdateInfo.UpdateFiles.ToList <string>();
            }
            else
            {
                _UpdateAppTimer.Start();
                return;
            }

            if (NeedUpdateFiles != null && NeedUpdateFiles.Count > 0)
            {
                AppFuns.ShowMessage($"发现新版本程序,点击确定开始升级。", $"新版本[{UpdateInfo.UpdateDate:yyyy-MM-dd HH:mm}]");
                WinUpdateDialog winUpdate = new WinUpdateDialog(NeedUpdateFiles);
                winUpdate.ShowDialog();
                if (!CheckDownResult(UpdateInfo))
                {
                    AppFuns.ShowMessage("下载升级文件不正确,无法更新。", "错误", isErr: true);
                    ShutDownApp();
                    return;
                }
                //升级程序路径。
                string updateProgram = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UpdateApp.exe");
                if (File.Exists(updateProgram))
                {
                    //下载成功,更新本地时间。
                    AppSet.LocalSetting.AppUpDateTime = UpdateInfo.UpdateDate;
                    if (DataRWLocalFileRepository.SaveObjToFile(AppSet.LocalSetting, AppSet.LocalSettingFileName))
                    {
                        //启动升级程序
                        _ = Task.Run(() =>
                        {
                            int UpdateExitCode = System.Diagnostics.Process.Start(updateProgram).ExitCode;
                        }).ConfigureAwait(false);
                    }
                }
                else
                {
                    AppFuns.ShowMessage("未找到更新程序,请与开发人员联系。", "错误", isErr: true);
                }
                //关闭本程序
                Thread.Sleep(500);
                ShutDownApp();
            }
            else
            {
                _UpdateAppTimer.Start();
            }
        }
Пример #11
0
        /// <summary>
        /// 从服务器读取本程序最新升级信息
        /// </summary>
        /// <returns></returns>
        public static async Task <AppUpdateInfo> GetAppUpdateInfo()
        {
            AppUpdateInfo UpdateInfo = await DataApiRepository.GetApiUri <AppUpdateInfo>(_ApiUrlBase + "UpdateFile/GetUpdateInfo").ConfigureAwait(false);

            return(UpdateInfo);
        }