コード例 #1
0
        public static async Task <UpdateResult> UpdateAsync(IRepositoryMod repository, StorageMod storage, IStorageMod implementation, CancellationToken cancellationToken, IProgress <FileSyncStats>?progress)
        {
            var logger = LogHelper.GetLoggerWithIdentifier(typeof(RepoSync), Guid.NewGuid().ToString());

            try
            {
                var repoSync = await BuildAsync(repository, storage, implementation, logger, cancellationToken);

                await repoSync.UpdateAsync(cancellationToken, progress);
            }
            catch (IOException e) when((e.HResult & 0xFFFF) == 32)  // 32: sharing violation, aka open in arma
            {
                logger.Error(e);
                return(UpdateResult.FailedSharingViolation);
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(UpdateResult.Failed);
            }

            logger.Trace("Progress: None");
            progress?.Report(new FileSyncStats(FileSyncState.None));
            return(UpdateResult.Success);
        }
コード例 #2
0
ファイル: MatchHash.cs プロジェクト: BeowulfStratOps/BSU
        // TODO: use more specialized interface to get files
        public static async Task <MatchHash> CreateAsync(IRepositoryMod mod, CancellationToken cancellationToken)
        {
            byte[]? modCppData = null;
            try
            {
                modCppData = await mod.GetFile("/mod.cpp", cancellationToken);
            }
            catch (Exception)
            {
                // ignored
            }

            string?name = null;

            if (modCppData != null)
            {
                name = ModUtil.ParseModCpp(Encoding.UTF8.GetString(modCppData)).GetValueOrDefault("name");
                if (name != null)
                {
                    name = CleanName(name);
                }
            }

            var pboNames = await mod.GetFileList(cancellationToken);

            var pboNameSet = pboNames.Where(f => AddonsPboRegex.IsMatch(f)).ToHashSet();

            return(new MatchHash(pboNameSet, name));
        }
コード例 #3
0
ファイル: VersionHash.cs プロジェクト: BeowulfStratOps/BSU
        // TODO: use more specialized interface to get files
        public static async Task <VersionHash> CreateAsync(IRepositoryMod mod, CancellationToken cancellationToken)
        {
            var files = await mod.GetFileList(cancellationToken);

            var hashes = new Dictionary <string, FileHash>();

            foreach (var file in files)
            {
                var hash = await mod.GetFileHash(file, cancellationToken);

                hashes.Add(file, hash);
            }
            return(new VersionHash(BuildHash(hashes)));
        }
コード例 #4
0
        private static async Task <RepoSync> BuildAsync(IRepositoryMod repository, StorageMod storage,
                                                        IStorageMod implementation, Logger logger, CancellationToken cancellationToken)
        {
            logger.Debug($"Building sync actions {storage} to {repository}");

            var allActions     = new List <SyncWorkUnit>();
            var repositoryList = await repository.GetFileList(cancellationToken);

            var storageList = await implementation.GetFileList(cancellationToken);

            var storageListCopy = new List <string>(storageList);

            foreach (var repoFile in repositoryList)
            {
                if (storageList.Contains(repoFile))
                {
                    var repoFileHash = await repository.GetFileHash(repoFile, cancellationToken);

                    var storageFileHash = await implementation.GetFileHash(repoFile, cancellationToken);

                    if (!repoFileHash.Equals(storageFileHash))
                    {
                        var fileSize = await repository.GetFileSize(repoFile, cancellationToken);

                        allActions.Add(new UpdateAction(repository, implementation, repoFile, fileSize));
                        storageListCopy.Remove(repoFile + ".part");
                    }

                    storageListCopy.Remove(repoFile);
                }
                else
                {
                    var fileSize = await repository.GetFileSize(repoFile, cancellationToken);

                    allActions.Add(new DownloadAction(repository, implementation, repoFile, fileSize));
                }
            }

            foreach (var storageModFile in storageListCopy)
            {
                allActions.Add(new DeleteAction(implementation, storageModFile));
            }

            logger.Debug($"Download actions: {allActions.OfType<DownloadAction>().Count()}");
            logger.Debug($"Update actions: {allActions.OfType<UpdateAction>().Count()}");
            logger.Debug($"Delete actions: {allActions.OfType<DeleteAction>().Count()}");

            return(new RepoSync(allActions, logger));
        }
コード例 #5
0
 public DownloadAction(IRepositoryMod repository, IStorageMod storage, string path, ulong fileSize) : base(storage, path)
 {
     _repository = repository;
     _fileSize   = fileSize;
 }
コード例 #6
0
 public Task <UpdateResult> Update(IRepositoryMod repositoryMod, MatchHash targetMatch, VersionHash targetVersion, IProgress <FileSyncStats>?progress,
                                   CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }