public ModificationPhaseFactory(IPofSerializer pofSerializer, IFileSystemProxy fileSystemProxy, TemporaryFileService temporaryFileService, ExeggutorService exeggutorService, ModificationPhaseManager phaseManager, ModificationLoader modificationLoader, ModificationViewModel viewModel, LeagueBuildUtilities leagueBuildUtilities, Modification modification)
 {
     this.pofSerializer = pofSerializer;
      this.fileSystemProxy = fileSystemProxy;
      this.temporaryFileService = temporaryFileService;
      this.exeggutorService = exeggutorService;
      this.phaseManager = phaseManager;
      this.modificationLoader = modificationLoader;
      this.viewModel = viewModel;
      this.leagueBuildUtilities = leagueBuildUtilities;
      this.modification = modification;
 }
        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);
        }
 public ModificationController(Modification modification, ModificationViewModel viewModel) {
    this.modification = modification;
    this.viewModel = viewModel;
 }