public void ResolveModification(string name)
        {
            var repositoryPath = Path.Combine(Path.Combine(clientConfiguration.UserDataDirectoryPath, "repositories"), name);
            var modification   = modificationLoader.FromPath(repositoryPath);

            leagueBuildUtilities.ResolveModification(modification, CancellationToken.None);
        }
        public void ImportingTaskStart()
        {
            var temporaryDirectory = TemporaryFileService.AllocateTemporaryDirectory(TimeSpan.FromHours(1));

            DirectoryHelpers.DirectoryCopy(Modification.RepositoryPath, temporaryDirectory, true);
            Directory.Move(temporaryDirectory, finalRepositoryPath);
            Modification = ModificationLoader.FromPath(finalRepositoryPath);
            PhaseFactory.SetModification(Modification);
            ViewModel.SetModification(Modification);

            var enabledComponent = Modification.GetComponent <EnabledComponent>();

            enabledComponent.IsEnabled = true;

            var thumbnailDirectory = Path.Combine(finalRepositoryPath, "thumbnails");

            FileSystemProxy.PrepareDirectory(thumbnailDirectory);
            var thumbnailGenerationTask = Task.Factory.StartNew(() => {
                using (var ms = new MemoryStream())
                    using (var writer = new BinaryWriter(ms)) {
                        PofSerializer.Serialize(writer, new ThumbnailGenerationParameters {
                            DestinationDirectory = thumbnailDirectory,
                            SourceDirectory      = importedDirectoryPath,
                            ThumbnailsToGenerate = 3
                        });
                        ExeggutorService.SpawnHatchling(
                            "thumbnail-generator",
                            new SpawnConfiguration {
                            InstanceName = "thumbnail-generator-" + DateTime.UtcNow.GetUnixTime(),
                            Arguments    = ms.GetBuffer()
                        });
                        var thumbnailComponent = Modification.GetComponent <ThumbnailComponent>();
                        thumbnailComponent.SelectThumbnailIfUnselected();
                    }
            }, TaskCreationOptions.LongRunning);

            var contentDirectory = Path.Combine(finalRepositoryPath, "content");

            FileSystemProxy.PrepareDirectory(contentDirectory);
            for (var i = 0; i < relativeImportedFilePaths.Length; i++)
            {
                var sourceFile      = Path.Combine(importedDirectoryPath, relativeImportedFilePaths[i]);
                var destinationFile = Path.Combine(contentDirectory, relativeImportedFilePaths[i]);
                FileSystemProxy.PrepareParentDirectory(destinationFile);
                FileSystemProxy.CopyFile(sourceFile, destinationFile);
                UpdateProgress(0.333 * ((double)i / relativeImportedFilePaths.Length));
            }

            LeagueBuildUtilities.ResolveModification(Modification, CancellationToken.None);
            UpdateProgress(0.666);

            LeagueBuildUtilities.CompileModification(Modification, CancellationToken.None);
            UpdateProgress(1);
            thumbnailGenerationTask.Wait();
            PhaseManager.Transition(PhaseFactory.Idle());
        }
Exemplo n.º 3
0
        public void ImportLegacyModification(string friendlyModificationName, string importedDirectoryPath, string[] importedFilePaths, LeagueModificationCategory category, ModificationImportWindow importWindow)
        {
            string repositoryName      = Util.ExtractFileNameTokens(friendlyModificationName).Select(token => token.ToLower()).Join("-");
            string finalRepositoryPath = Path.Combine(repositoriesDirectory, repositoryName);
            var    temporaryDirectory  = temporaryFileService.AllocateTemporaryDirectory(TimeSpan.FromHours(1));
            var    workingDirectory    = Path.Combine(temporaryDirectory, "working");
            var    contentDirectory    = Path.Combine(workingDirectory, "content");
            var    temporaryNestPath   = Path.Combine(temporaryDirectory, "working_nest");

            fileSystemProxy.PrepareDirectory(contentDirectory);
            fileSystemProxy.PrepareDirectory(temporaryNestPath);

            var temporaryNest = new LocalDargonNest(temporaryNestPath);
            var inMemoryEgg   = new InMemoryEgg(repositoryName, "legacy", workingDirectory);

            temporaryNest.InstallEgg(inMemoryEgg);

            var temporaryEggPath = Path.Combine(temporaryNestPath, inMemoryEgg.Name);

            var temporaryModification = modificationLoader.FromPath(temporaryEggPath);
            var info = temporaryModification.GetComponent <InfoComponent>();

            info.Id   = Guid.NewGuid();
            info.Name = friendlyModificationName;

            var leagueComponent = temporaryModification.GetComponent <LeagueMetadataComponent>();

            leagueComponent.Category = category;

            var viewModel  = new ModificationViewModel();
            var controller = new ModificationController(null, viewModel);

            viewModel.SetController(controller);
            viewModel.SetModification(temporaryModification);

            Application.Current.Dispatcher.BeginInvoke(
                new Action(() => {
                modificationViewModels.Add(viewModel);

                importWindow.Close();

                var modificationPhaseManager = new ModificationPhaseManager();
                var modificationPhaseFactory = new ModificationPhaseFactory(pofSerializer, fileSystemProxy, temporaryFileService, exeggutorService, modificationPhaseManager, modificationLoader, viewModel, leagueBuildUtilities, temporaryModification);
                controller.SetModificationPhaseManager(modificationPhaseManager);
                modificationPhaseManager.Transition(modificationPhaseFactory.Importing(importedDirectoryPath, importedFilePaths, finalRepositoryPath));
                controller.Initialize();
            }), DispatcherPriority.Send
                );

            //         var modification = modificationLoader.FromPath(e.FullPath);

            //         fileSystemProxy.MoveDirectory(temporaryEggPath, finalRepositoryPath);

            return;


//         foreach (var relativeFilePath in importedRelativeFilePaths) {
//            var importedFile = Path.Combine(modificationRoot, relativeFilePath);
//            var contentFile = Path.Combine(contentDirectory, relativeFilePath);
//            fileSystemProxy.PrepareParentDirectory(contentFile);
//            fileSystemProxy.CopyFile(importedFile, contentFile);
//         }
//
//         var workingDirectoryInfo = fileSystemProxy.GetDirectoryInfo(workingDirectory);

//
//         var destinationNestLockPath = Path.Combine(repositoriesDirectory, "LOCK");
//         using (fileSystemProxy.OpenFile(destinationNestLockPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) {
//            var temporaryNest = Path.Combine(temporaryDirectory, "working_nest");
//            fileSystemProxy.PrepareDirectory(temporaryNest);
//            var inMemoryEgg = new InMemoryEgg(repositoryName, "legacy", workingDirectory);
//            var modificationsNest = new LocalDargonNest(temporaryNest);
//            modificationsNest.InstallEgg(inMemoryEgg);
//
//            var temporaryEggPath = Path.Combine(temporaryNest, inMemoryEgg.Name);
//            fileSystemProxy.MoveDirectory(temporaryEggPath, finalRepositoryPath);
//         }
//
//         fileSystemProxy.DeleteDirectory(temporaryDirectory, true);
        }
Exemplo n.º 4
0
        private void HandleRepositoriesDirectoryModified(object sender, FileSystemEventArgs e)
        {
            switch (e.ChangeType)
            {
            case WatcherChangeTypes.Changed:
                break;

            case WatcherChangeTypes.Created:
                var fileInfo = fileSystemProxy.GetFileInfo(e.FullPath);
                if (fileInfo.Attributes.HasFlag(FileAttributes.Directory))
                {
                    if (fileInfo.Name.StartsWith("."))
                    {
                        logger.Info($"Ignoring modification candidate {fileInfo.Name} as name has leading period.");
                    }
                    else if (displayedModificationNames.Contains(fileInfo.Name))
                    {
                        logger.Info($"Ignoring modification candidate {fileInfo.Name} as view model already exists.");
                    }
                    else
                    {
                        var modification = modificationLoader.FromPath(e.FullPath);
                        var viewModel    = new ModificationViewModel();
                        var controller   = new ModificationController(modification, viewModel);
                        viewModel.SetController(controller);
                        viewModel.SetModification(modification);
                        var modificationPhaseManager = new ModificationPhaseManager();
                        var modificationPhaseFactory = new ModificationPhaseFactory(pofSerializer, fileSystemProxy, temporaryFileService, exeggutorService, modificationPhaseManager, modificationLoader, viewModel, leagueBuildUtilities, modification);
                        modificationPhaseManager.Transition(modificationPhaseFactory.Idle());
                        controller.SetModificationPhaseManager(modificationPhaseManager);
                        controller.Initialize();

                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => {
                            modificationViewModels.Add(viewModel);
                        }));
                    }
                }
                break;

            case WatcherChangeTypes.Deleted:
                var removedViewModel = modificationViewModels.FirstOrDefault(x => x.RepositoryName.Equals(e.Name, StringComparison.OrdinalIgnoreCase));
                if (removedViewModel == null)
                {
                    logger.Error("Failed to find viewmodel match for removed directory " + e.FullPath);
                }
                else
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => {
                        modificationViewModels.Remove(removedViewModel);
                    }));
                }
                break;

            case WatcherChangeTypes.Renamed:
                var renamedArgs     = (RenamedEventArgs)e;
                var parentDirectory = new FileInfo(renamedArgs.FullPath).Directory;
                HandleRepositoriesDirectoryModified(sender, new FileSystemEventArgs(WatcherChangeTypes.Deleted, parentDirectory.FullName, renamedArgs.OldName));
                HandleRepositoriesDirectoryModified(sender, new FileSystemEventArgs(WatcherChangeTypes.Created, parentDirectory.FullName, renamedArgs.Name));
                break;
            }
        }