예제 #1
0
        /// <summary>
        /// 写入更新配置文件
        /// </summary>
        /// <param name="vm"></param>
        public static void UpdatePluginConfig(VersionModel vm)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(vm.PluginName) && !string.IsNullOrWhiteSpace(vm.PluginEntry))
                {
                    XElement xe     = XElement.Load(R.Files.Plugins);
                    XElement record = xe.Elements("Item").FirstOrDefault(x => x.Attribute("Name").Value == vm.PluginName);
                    if (record != null)
                    {
                        //如果xml包含改插件,则更新
                        string entryFile = DirTool.IsDriver(vm.PluginEntry) ? vm.PluginEntry : DirTool.Combine(R.Paths.ProjectRoot, vm.PluginEntry);

                        record.Attribute("Entry").Value   = entryFile;
                        record.Attribute("Version").Value = vm.VersionNumber;
                    }
                    else
                    {
                        //如果xml不包含插件,则添加插件
                        string entryFile = DirTool.IsDriver(vm.PluginEntry) ? vm.PluginEntry : DirTool.Combine(R.Paths.ProjectRoot, vm.PluginEntry);

                        XElement insertRec = new XElement("Item", new XAttribute("Name", vm.PluginName), new XAttribute("Entry", entryFile), new XAttribute("Version", vm.VersionNumber));
                        xe.Add(insertRec);
                    }
                    xe.Save(R.Files.Plugins);
                }
            }
            catch (Exception e)
            {
                R.Log.e("修改插件配置信息出错:" + e.Message);
            }
        }
예제 #2
0
 public static void AfterUpdate(List <string> killProcess, List <string> startProcess)
 {
     if (ListTool.HasElements(killProcess))
     {
         foreach (var p in killProcess)
         {
             ProcessTool.KillProcess(p);
         }
     }
     if (ListTool.HasElements(startProcess))
     {
         foreach (var p in startProcess)
         {
             string file = DirTool.IsDriver(p) ? p : DirTool.Combine(R.Paths.ProjectRoot, p);
             ProcessTool.StartProcess(file);
         }
     }
 }
예제 #3
0
 public static void BeforeUpdate(VersionModel vm)
 {
     if (ListTool.HasElements(vm.BeforeUpdateKillProcess))
     {
         foreach (var p in vm.BeforeUpdateKillProcess)
         {
             ProcessTool.KillProcess(p);
         }
     }
     if (ListTool.HasElements(vm.BeforeUpdateStartProcess))
     {
         foreach (var p in vm.BeforeUpdateStartProcess)
         {
             string file = DirTool.IsDriver(p) ? p : DirTool.Combine(R.Paths.ProjectRoot, p);
             ProcessTool.StartProcess(file);
         }
     }
 }
예제 #4
0
        public static void Clean(VersionModel vm)
        {
            //清理临时文件夹
            if (Directory.Exists(R.Paths.Temp))
            {
                try { Directory.Delete(R.Paths.Temp, true); } catch { }
            }
            //清理指定文件
            var cleanFile = vm.FileList.Where(x => x.IsClean == true);

            foreach (var file in cleanFile)
            {
                string fff = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : R.Paths.ProjectRoot + file.LocalFile;
                if (File.Exists(fff))
                {
                    try { File.Delete(fff); } catch { }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 下载要更新的文件
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        private bool UpdateDownload(VersionModel vm)
        {
            FileCodeTool fcode    = new FileCodeTool();
            var          downFile = vm.FileList.Where(x => x.IsClean == false).ToList();

            if (vm != null && ListTool.HasElements(downFile))
            {
                for (int i = 0; i < downFile.Count(); i++)
                {
                    VersionFile file       = downFile[i];
                    string      serverFile = DirTool.Combine(vm.ServerPath, file.ServerFile);
                    string      tempFile   = DirTool.Combine(R.Paths.Temp, DownTemp, file.ServerFile);                                                 //下载到目标位置(带文件名)
                    string      localFile  = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile); //旧文件位置
                    if (fcode.GetMD5(localFile) != file.FileMD5)
                    {
                        UIUpdateDetail("正在下载:" + Path.GetFileName(file.ServerFile));
                        R.Log.v(string.Format("{0} 文件有更新,正在下载文件", Path.GetFileName(file.ServerFile)));
                        FtpTool ftp = new FtpTool(R.Settings.FTP.Address, R.Settings.FTP.Account, R.Settings.FTP.Password);
                        if (!ftp.Download(serverFile, tempFile))
                        {
                            if (!ftp.Download(serverFile, tempFile))
                            {
                                if (!ftp.Download(serverFile, tempFile))
                                {
                                    R.Log.w(string.Format("{0} 文件下载失败", Path.GetFileName(file.ServerFile)));
                                    return(false);
                                }
                            }
                        }
                    }
                    else
                    {
                        UIUpdateDetail("文件已存在:" + Path.GetFileName(file.ServerFile));
                        R.Log.v(string.Format("{0} 文件不需要更新,已跳过该文件", Path.GetFileName(file.ServerFile)));
                    }
                    UIProgress(i + 1, downFile.Count());
                }
                return(true);
            }
            return(false);
        }
예제 #6
0
        /// <summary>
        /// 更新回滚
        /// </summary>
        /// <param name="vm"></param>
        private void UpdateRollback(VersionModel vm)
        {
            var backFile = vm.FileList.Where(x => x.IsClean == false);

            foreach (var file in backFile)
            {
                string tempBack  = DirTool.Combine(R.Paths.Temp, BackupTemp, file.ServerFile);                                               //备份到目标位置(带文件名)
                string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile); //旧文件位置

                //还原备份文件
                if (File.Exists(tempBack))
                {
                    try
                    {
                        DirTool.Create(DirTool.GetFilePath(localFile));
                        File.Copy(tempBack, localFile, true);
                        UIUpdateDetail("正在还原备份文件:" + Path.GetFileName(file.LocalFile));
                    }
                    catch (Exception e) { }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 备份并替换文件
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        private bool UpdateInsteadAndBackup(VersionModel vm)
        {
            var insteadFile = vm.FileList.Where(x => x.IsClean == false);

            foreach (var file in insteadFile)
            {
                string tempDown  = DirTool.Combine(R.Paths.Temp, DownTemp, file.ServerFile);                                                 //下载到目标位置(带文件名)
                string tempBack  = DirTool.Combine(R.Paths.Temp, BackupTemp, file.ServerFile);                                               //备份到目标位置(带文件名)
                string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile); //旧文件位置

                //备份文件
                if (File.Exists(localFile) && File.Exists(tempDown))
                {
                    try
                    {
                        DirTool.Create(DirTool.GetFilePath(tempBack));
                        File.Copy(localFile, tempBack, true);
                        UIUpdateDetail("正在备份:" + Path.GetFileName(tempBack));
                    }
                    catch (Exception e) { }
                }
                //替换文件
                if (File.Exists(tempDown))
                {
                    try
                    {
                        DirTool.Create(DirTool.GetFilePath(localFile));
                        File.Copy(tempDown, localFile, true);
                        UIUpdateDetail("正在更新:" + Path.GetFileName(file.LocalFile));
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }