예제 #1
0
        private static void SynchronizeDirectory(Sync sync, IFileHandler contentFileHandler, IFileHandler outputFileHandler)
        {
            switch (sync.SyncType)
            {
            case SyncType.SourceToTarget:
                if (outputFileHandler.DirectoryExists(sync.TargetPath))
                {
                    _logger.Debug(@"{SyncLogType}: (already exists) [{TargetPath}]", SyncLogType.CreateTargetDirectory.GetDescription(), sync.TargetPath);
                }
                else
                {
                    _logger.Information(@"{SyncLogType}: [{TargetPath}]", SyncLogType.CreateTargetDirectory.GetDescription(), sync.TargetPath);
                    outputFileHandler.DirectoryCreateDirectory(sync.TargetPath);
                }

                break;

            case SyncType.TargetToSource:
                if (contentFileHandler.DirectoryExists(sync.SourcePath))
                {
                    _logger.Debug(@"{SyncLogType}: (already exists) [{SourcePath}]", SyncLogType.CreateSourceDirectory.GetDescription(), sync.SourcePath);
                }
                else
                {
                    _logger.Information(@"{SyncLogType}: [{SourcePath}]", SyncLogType.CreateSourceDirectory.GetDescription(), sync.SourcePath);
                    contentFileHandler.DirectoryCreateDirectory(sync.SourcePath);
                }

                if (outputFileHandler.DirectoryExists(sync.TargetPath) == false)
                {
                    _logger.Information(@"{SyncLogType}: [{TargetPath}]", SyncLogType.CreateTargetDirectory.GetDescription(), sync.TargetPath);
                    outputFileHandler.DirectoryCreateDirectory(sync.TargetPath);
                }

                break;

            case SyncType.DeleteTarget:
                if (outputFileHandler.DirectoryExists(sync.TargetPath))
                {
                    _logger.Information(@"{SyncLogType}: [{TargetPath}]", SyncLogType.DeleteTargetDirectory.GetDescription(), sync.TargetPath);
                    outputFileHandler.DirectoryDelete(sync.TargetPath, recursive: true);
                }
                else
                {
                    _logger.Debug(@"{SyncLogType}: (already deleted) [{TargetPath}]", SyncLogType.DeleteTargetDirectory.GetDescription(), sync.TargetPath);
                }

                break;

            case SyncType.Unknown:
            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #2
0
        private static void AddContentToSyncList(string sourceBasePath, IFileHandler outputFileHandler, IList <Package> packages,
                                                 string contentFolderName, SyncType syncType, List <Sync> syncList, AliasService aliasService)
        {
            int packageCnt = 0;

            foreach (var package in packages)
            {
                ProgressBar.DrawProgressBar($"AddContentToSyncList [{contentFolderName}]", packageCnt++, packages.Count);

                var packageContentFolderBasePath = _pathService.Combine(sourceBasePath, package.Path, contentFolderName);
                var packageContentLhaBasePath    = _pathService.Combine(sourceBasePath, package.Path, contentFolderName + ".lha");
                if (Directory.Exists(packageContentFolderBasePath) && File.Exists(packageContentLhaBasePath))
                {
                    throw new Exception($"Package [{package.Path}] has both [content] folder and [content.lha].");
                }

                string packageContentBasePath;
                if (File.Exists(packageContentLhaBasePath))
                {
                    packageContentBasePath = packageContentLhaBasePath;
                }
                else if (Directory.Exists(packageContentFolderBasePath))
                {
                    packageContentBasePath = packageContentFolderBasePath;
                }
                else
                {
                    continue;
                }

                using (var contentFileHandler = FileHandlerFactory.Create(_logger, packageContentBasePath))
                {
                    var packageOutputPath = "";
                    var sourcePath        = "";
                    var packageEntries    = contentFileHandler.DirectoryGetFileSystemEntriesRecursive(sourcePath);
                    foreach (var packageEntry in packageEntries)
                    {
                        var outputPath = aliasService.TargetAliasToOutputPath(packageEntry);

                        var packageEntryFileName = _pathService.GetFileName(outputPath);
                        if (ShouldContentReverseAll(packageEntryFileName))
                        {
                            var contentReversePackageEntryPath = _pathService.GetDirectoryName(outputPath);
                            var contentReversePackageSubPath   = RemoveRoot(sourcePath, contentReversePackageEntryPath);
                            var contentReverseFileOutputPath   = _pathService.Combine(packageOutputPath, contentReversePackageSubPath);
                            if (outputFileHandler.DirectoryExists(contentReverseFileOutputPath))
                            {
                                var innerContentReversePackageEntries = outputFileHandler.DirectoryGetFileSystemEntriesRecursive(contentReverseFileOutputPath);
                                foreach (var innerContentReversePackageEntry in innerContentReversePackageEntries)
                                {
                                    var innerContentReversePackageSubPath = RemoveRoot(packageOutputPath, innerContentReversePackageEntry);
                                    var innerContentReverseSourcePath     = _pathService.Combine(sourcePath, innerContentReversePackageSubPath);

                                    var innerSync = new Sync
                                    {
                                        PackageContentBasePath = packageContentBasePath,
                                        SourcePath             = innerContentReverseSourcePath,
                                        TargetPath             = innerContentReversePackageEntry,
                                        SyncType = syncType,
                                        FileType = outputFileHandler.GetFileType(innerContentReversePackageEntry)
                                    };

                                    syncList.Add(innerSync);
                                }
                            }
                        }
                        else
                        {
                            var packageSubPath = RemoveRoot(sourcePath, outputPath);
                            var fileOutputPath = _pathService.Combine(packageOutputPath, packageSubPath);
                            var sync           = new Sync
                            {
                                PackageContentBasePath = packageContentBasePath,
                                SourcePath             = packageEntry,
                                TargetPath             = fileOutputPath,
                                SyncType = syncType,
                                FileType = contentFileHandler.GetFileType(packageEntry)
                            };

                            syncList.Add(sync);
                        }
                    }
                }
            }
        }