Beispiel #1
0
        private static bool FetchUpdatePackage(VersionUpdateInfo updateInfo)
        {
            string updatePackageLocalFile = Path.Combine(UPDATE_PACKAGE_PATH, string.Format("{0}.zip", updateInfo.MD5));
            bool   downloadResult         = false;
            bool   resolveResult          = false;
            int    downloadTimes          = 0;

            do
            {
                downloadResult = DownloadUpdatePackage(updateInfo.Url, updatePackageLocalFile);
                if (downloadResult)
                {
                    resolveResult = ResolveUpdatePackage(updateInfo, updatePackageLocalFile);
                    if (resolveResult)
                    {
                        break;
                    }
                }
                downloadTimes++;
            } while (downloadTimes < RETRY_TIMES);

            if (downloadResult && resolveResult)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        private static bool ResolveUpdatePackage(VersionUpdateInfo updateInfo, string updatePackageLocalFile)
        {
            bool isMatch;

            MD5Helper.FileMD5ErrorMode errCode;
            isMatch = CheckUpdatePackageMD5(updatePackageLocalFile, updateInfo.MD5, out errCode);
            if (errCode != MD5Helper.FileMD5ErrorMode.OK || !isMatch)
            {
                return(false);
            }
            string upzipUpdatePackagePath = Path.Combine(UNZIP_UPDATE_PACKAGE_PATH, updateInfo.MD5);

            if (!UnZipUpdatePackage(updatePackageLocalFile, upzipUpdatePackagePath))
            {
                return(false);
            }

            if (GetUpdateDetailsList(Path.Combine(upzipUpdatePackagePath, UPATE_DETAILS_FILE_NAME)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    /// <summary>
    /// 获得先前的版本更新信息
    /// </summary>
    /// <param name="appVersion"></param>
    /// <returns></returns>
    private VersionUpdateInfo GetPreviousVersionUpdateInfo(AppVersion appVersion)
    {
        // 缺省版本信息
        VersionUpdateInfo versionUpdateInfo = new VersionUpdateInfo()
        {
            VersionUpdateItems = new List <VersionUpdateItem>()
        };

        do
        {
            if (appVersion.Revision == 0)
            {
                break;
            }

            string previousVersionPath = GetPreviousLastestVersionPath(PreviousVersion());
            if (string.IsNullOrEmpty(previousVersionPath))
            {
                break;
            }

            string previousUpdateInfoPath = previousVersionPath + "/Snapshot/" + VersionConst.PatchInfoFileName;
            if (File.Exists(previousUpdateInfoPath))
            {
                var oldUpdateInfo = JsonUtility.FromJson <VersionUpdateInfo>(File.ReadAllText(previousUpdateInfoPath));
                if (oldUpdateInfo != null && oldUpdateInfo.VersionUpdateItems != null)
                {
                    versionUpdateInfo = oldUpdateInfo;
                }
            }
        } while (false);

        return(versionUpdateInfo);
    }
    /// <summary>
    /// 把生成的补丁放到版本更新里
    /// </summary>
    /// <param name="versionUpdateInfo"></param>
    private void AddPatchToVersionUpdateInfo(VersionUpdateInfo versionUpdateInfo)
    {
        foreach (var oneItem in versionUpdateInfo.VersionUpdateItems)
        {
            if (oneItem.Version == _appVersion)
            {
                List <PatchInfo> newPatchs = new List <PatchInfo>();
                if (oneItem.Patches != null)
                {
                    foreach (var onePatch in oneItem.Patches)
                    {
                        if (onePatch.RevisionNum >= _appVersion.Revision)
                        {
                            break;
                        }

                        newPatchs.Add(onePatch);
                    }
                }

                // 增加新增patch
                string patchPath = PatchDir + "/" + _patchName + ".zip";
                newPatchs.Add(new PatchInfo()
                {
                    PatchName   = _patchName + ".zip",
                    FileSize    = (ulong)FileUtils.GetFileLength(patchPath),
                    RevisionNum = _appVersion.Revision,
                    Md5         = GameUtil.md5file(patchPath)
                });

                oneItem.Patches = newPatchs;
                break;
            }
        }
    }
Beispiel #5
0
 public Result UploadFileItem([FromForm] IFormCollection formCollection)
 {
     try
     {
         VersionUpdateInfo updateInfo = MemoryCache.GetValue <VersionUpdateInfo>(CacheKey.UploadCacheFileName);
         if (updateInfo == null)
         {
             return("必须先上传版本信息!");
         }
         //要写入的文件流
         MemoryStream   writeStream = null;
         FormCollection form        = ((FormCollection)formCollection);
         bool           isFirst     = form["First"][0].ToBaseType <bool>();
         bool           isCenter    = form["Center"][0].ToBaseType <bool>();
         bool           isEnd       = form["End"][0].ToBaseType <bool>();
         string         md5         = form["MD5"][0].ToBaseType <string>();
         IFormFile      file        = form.Files.First();
         string         filename    = Path.Combine(updateInfo.Path, file.FileName);
         string         root        = Path.GetDirectoryName(filename);
         //检测路径是否存在
         if (System.IO.File.Exists(filename))
         {
             System.IO.File.Delete(filename);
         }
         if (!Directory.Exists(root))
         {
             Directory.CreateDirectory(root);
         }
         if (isFirst)
         {
             writeStream = new MemoryStream();
             MemoryCache.SetValue(md5, writeStream, DateTime.Now + TimeSpan.FromMinutes(10));
         }
         else
         {
             writeStream = MemoryCache.GetValue <MemoryStream>(md5) as MemoryStream;
         }
         // 复制文件
         file.CopyTo(writeStream);
         if (isEnd)
         {
             using (FileStream stream = System.IO.File.Create(filename))
             {
                 writeStream.Position = 0;
                 writeStream.CopyTo(stream);
                 stream.Flush();
                 writeStream.Flush();
                 writeStream.Close();
             }
         }
         return(Result.Success("成功!"));
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
    public void SaveFiles(VersionUpdateInfo versionUpdateInfo)
    {
        GameBuilder.DoSaveVersionFile(_appVersion,
                                      PlatformEditorUtils.GetBuildToolVersionDir(_buildTarget) + "/" + VersionConst.VersionFileName);

        SaveUpdateInfo(versionUpdateInfo);

        CopyToDiffPath();
    }
    /// <summary>
    /// 保存版本信息
    /// </summary>
    /// <param name="versionUpdateInfo"></param>
    private void SaveUpdateInfo(VersionUpdateInfo versionUpdateInfo)
    {
        if (_appVersion.Revision != 0)
        {
            AddPatchToVersionUpdateInfo(versionUpdateInfo);
        }

        var json = JsonUtility.ToJson(versionUpdateInfo, true);

        File.WriteAllText(CurrentBuildUpdateInfoPath(), json);
    }
Beispiel #8
0
 public Result UpdateVersion(string oldversion, string targetversion)
 {
     try
     {
         oldversion    = oldversion.FlushVersion();
         targetversion = targetversion.FlushVersion();
         VersionUpdateInfo old    = VersionUpdateService.GetVersionInfoByVersion(oldversion);
         VersionUpdateInfo target = VersionUpdateService.GetVersionInfoByVersion(targetversion);
         if (target == null)
         {
             return("请求的版本不存在!");
         }
         //获取所有相差的版本信息
         List <Versioninfo> versioninfos = null;
         if (old == null)
         {
             versioninfos = VersionUpdateService.GetBeforeVersion(targetversion);
         }
         else
         {
             //如果反向更新
             if (targetversion.ToVersion() < oldversion.ToVersion())
             {
                 versioninfos = VersionUpdateService.GetBeforeVersion(oldversion);
                 List <Versioninfo> removes = new List <Versioninfo>();
                 foreach (var item in versioninfos)
                 {
                     if (item.Value == targetversion)
                     {
                         break;
                     }
                     removes.Add(item);
                 }
                 //删除多余的
                 foreach (var item in removes)
                 {
                     versioninfos.Remove(item);
                 }
             }
             else
             {
                 versioninfos = VersionUpdateService.GetVersionBetween(oldversion, targetversion);
             }
         }
         return(Result.Success("", StaticHelp.ConvertToHistory(versioninfos,
                                                               CacheKey, oldversion.ToVersion() > targetversion.ToVersion())));
     }
     catch (Exception ex)
     {
         return(Result.Fail(ex.Message));
     }
 }
Beispiel #9
0
        /// <summary>
        /// 根据历史版本的改动获取所有需要下载的文件的集合
        /// </summary>
        /// <param name="historys">历史改动版本</param>
        /// <param name="cacheKey">配置</param>
        /// <param name="isDesc">是否逆向操作</param>
        /// <returns>需要修改的文件信息</returns>
        public static VersionUpdateInfo ConvertToHistory(List <Versioninfo> historys, CacheKey cacheKey, bool isDesc = false)
        {
            VersionUpdateInfo version = new VersionUpdateInfo();

            if (isDesc == false)
            {
                //遍历历史
                foreach (var item in historys)
                {
                    //获取根目录
                    string root = cacheKey.UploadCacheFileRootPath.FromProjectRootCombine(item.Path, cacheKey.VersionUpdateFileSaveName);
                    //读取对应版本的配置文件
                    VersionUpdateInfo info = root.ReadFromFile <VersionUpdateInfo>();
                    foreach (var fileInfo in info.Files.Values)
                    {
                        version.AddFileInfo(fileInfo);
                    }
                }
            }
            else
            {
                for (int i = historys.Count - 1; i > 0; i--)
                {
                    Versioninfo item = historys[i];
                    //获取根目录
                    string root = cacheKey.UploadCacheFileRootPath.FromProjectRootCombine(item.Path, cacheKey.VersionUpdateFileSaveName);

                    //读取对应版本的配置文件
                    VersionUpdateInfo info = root.ReadFromFile <VersionUpdateInfo>();
                    foreach (var fileInfo in info.Files.Values)
                    {
                        if (fileInfo.Status == FileStatus.Add)
                        {
                            fileInfo.Status = FileStatus.Delete;
                        }
                        else if (fileInfo.Status == FileStatus.Delete)
                        {
                            fileInfo.Version = historys[i - 1].Value;
                            fileInfo.Status  = FileStatus.Add;
                        }
                        else if (fileInfo.Status == FileStatus.Modify)
                        {
                            fileInfo.Version = historys[i - 1].Value;
                            fileInfo.Status  = FileStatus.Modify;
                        }
                        version.AddFileInfo(fileInfo);
                    }
                }
            }
            return(version);
        }
    /// <summary>
    /// 验证合理性
    /// </summary>
    /// <returns></returns>
    VersionUpdateInfo Validate()
    {
        VersionUpdateInfo updateInfo = GetPreviousVersionUpdateInfo(_appVersion);

        VersionUpdateItem currentVersionItem = null;

        foreach (var oneItem in updateInfo.VersionUpdateItems)
        {
            if (oneItem.Version.IsSameVersionSame(_appVersion))
            {
                currentVersionItem = oneItem;
                break;
            }
        }

        if (currentVersionItem != null)
        {
            // 如果版本都已经比我们>=了
            if (currentVersionItem.Version > _appVersion ||
                (currentVersionItem.Version == _appVersion && _appVersion.Revision != 0))
            {
                Debug.LogErrorFormat("cannt overwrite [{0}] , it >= my version [{1}]", currentVersionItem.Version, _appVersion);
                return(null);
            }
        }

        AppVersion previousVersion = currentVersionItem == null ? new AppVersion(): currentVersionItem.Version;

        if (_appVersion.Revision != 0 && previousVersion.Revision + 1 != _appVersion.Revision)
        {
            Debug.LogErrorFormat("previous version [{0}]'s revision add one != patched version [{1}]", previousVersion, _appVersion);
            return(null);
        }

        // new update info
        if (currentVersionItem == null || !currentVersionItem.Version.IsSameVersionSame(_appVersion))
        {
            updateInfo.VersionUpdateItems.Add(new VersionUpdateItem()
            {
                Version = _appVersion
            });
        }
        else
        {
            currentVersionItem.Version = _appVersion;
        }

        return(updateInfo);
    }
Beispiel #11
0
 public Result UploadInfo([FromBody] VersionUpdateInfo versioninfo)
 {
     try
     {
         if (versioninfo.FlushVersion() == false)
         {
             return("版本号异常!");
         }
         string root = Path.Combine(AppContext.BaseDirectory, CacheKey.UploadCacheFileRootPath, versioninfo.Version);
         //如果文件夹存在,进行删除
         if (Directory.Exists(root) || VersionUpdateService.GetVersionByVersion(versioninfo.Version) != null)
         {
             return("已经存在该版本,不可以进行覆盖!");
         }
         else
         {
             Directory.CreateDirectory(root);
         }
         //版本信息
         Versioninfo version = new Versioninfo();
         version.Path          = versioninfo.Version;
         version.Value         = versioninfo.Version;
         version.UpdateMessage = versioninfo.Message;
         versioninfo.Path      = root;
         //添加版本
         VersionUpdateService.AddVersion(version);
         //更新当前最新的正在上传的版本信息
         MemoryCache.SetValue(CacheKey.UploadCacheFileName, versioninfo);
         //保存版本更新内容
         versioninfo.ToFile(root.Combine(CacheKey.VersionUpdateFileSaveName));
         //返回成功
         return(Result.Success(null));
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         return(Result.Fail(ex.Message));
     }
 }
Beispiel #12
0
        public Result UploadFile([FromForm] IFormCollection formCollection)
        {
            try
            {
                VersionUpdateInfo updateInfo = MemoryCache.GetValue <VersionUpdateInfo>(CacheKey.UploadCacheFileName);
                if (updateInfo == null)
                {
                    return("必须先上传版本信息!");
                }

                foreach (IFormFile file in ((FormCollection)formCollection).Files)
                {
                    StreamReader reader   = new StreamReader(file.OpenReadStream());
                    string       filename = Path.Combine(updateInfo.Path, file.FileName);
                    if (System.IO.File.Exists(filename))
                    {
                        System.IO.File.Delete(filename);
                    }
                    string root = Path.GetDirectoryName(filename);
                    if (!Directory.Exists(root))
                    {
                        Directory.CreateDirectory(root);
                    }
                    using (FileStream fs = System.IO.File.Create(filename))
                    {
                        // 复制文件
                        file.CopyTo(fs);
                        // 清空缓冲区数据
                        fs.Flush();
                    }
                }
                return(Result.Success("成功!"));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Beispiel #13
0
 private static bool ApplyUpdatePackage(VersionUpdateInfo updateInfo)
 {
     try
     {
         foreach (var item in _updateDetailsList)
         {
             if (item.Type == TargetType.File)
             {
                 IOHelper.CopyFile(Path.Combine(Path.Combine(UNZIP_UPDATE_PACKAGE_PATH, updateInfo.MD5), item.UpdateSource), Path.Combine(CURRENT_PATH, item.UpdateTarget));
             }
             else if (item.Type == TargetType.Folder)
             {
                 IOHelper.CopyFolder(Path.Combine(Path.Combine(UNZIP_UPDATE_PACKAGE_PATH, updateInfo.MD5), item.UpdateSource), Path.Combine(CURRENT_PATH, item.UpdateTarget));
             }
         }
     }
     catch (Exception ex)
     {
         System.Console.WriteLine("StartOldSoftWare:Move directory error," + ex.ToString());
         return(false);
     }
     return(true);
 }