public void CreateArchiveWithNoFiles_ShouldThrow() { var directoryHelper = new TestDirectoryHelper(GetType()); directoryHelper.SetUp(); var testDir = directoryHelper.Directory.CreateSubdirectory("CreateArchiveWithNoFiles_ShouldThrow"); var archiveFiles = new ArchiveFiles(new HICLoadConfigurationFlags()); var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "dataset"); var job = Mock.Of <IDataLoadJob>(j => j.DataLoadInfo == Mock.Of <IDataLoadInfo>()); job.LoadDirectory = loadDirectory; try { archiveFiles.Run(job, new GracefulCancellationToken()); foreach (FileInfo fileInfo in loadDirectory.ForArchiving.GetFiles("*.zip")) { Console.WriteLine("About to throw SetUp because of zip file:" + fileInfo.FullName); } Assert.IsFalse(loadDirectory.ForArchiving.GetFiles("*.zip").Any(), "There should not be any zip files in the archive directory!"); } finally { directoryHelper.TearDown(); } }
public IDataLoadExecution Create(IDataLoadEventListener postLoadEventListener) { var loadArgsDictionary = new LoadArgsDictionary(LoadMetadata, _databaseConfiguration.DeployInfo); //warn user about disabled tasks var processTasks = LoadMetadata.ProcessTasks.ToList(); foreach (IProcessTask task in processTasks .Where(p => p.IsDisabled)) { postLoadEventListener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning, "Found disabled ProcessTask" + task)); } //Get all the runtime tasks which are not disabled var factory = new RuntimeTaskPackager(processTasks.Where(p => !p.IsDisabled), loadArgsDictionary.LoadArgs, _cataloguesToLoad, _repository); var getFiles = new LoadFiles(factory.GetRuntimeTasksForStage(LoadStage.GetFiles)); var mounting = new PopulateRAW(factory.GetRuntimeTasksForStage(LoadStage.Mounting), _databaseConfiguration); var adjustRaw = factory.CreateCompositeDataLoadComponentFor(LoadStage.AdjustRaw, "Adjust RAW"); var migrateToStaging = new MigrateRAWToStaging(_databaseConfiguration, _loadConfigurationFlags); var adjustStaging = factory.CreateCompositeDataLoadComponentFor(LoadStage.AdjustStaging, "Adjust Staging"); var migrateStagingToLive = new MigrateStagingToLive(_databaseConfiguration, _loadConfigurationFlags); var postLoad = factory.CreateCompositeDataLoadComponentFor(LoadStage.PostLoad, "Post Load"); var archiveFiles = new ArchiveFiles(_loadConfigurationFlags); var loadStagingDatabase = new CompositeDataLoadComponent(new List <IDataLoadComponent> { mounting, adjustRaw, migrateToStaging }); var adjustStagingAndMigrateToLive = new CompositeDataLoadComponent(new List <IDataLoadComponent> { loadStagingDatabase, adjustStaging, migrateStagingToLive, postLoad }); var components = new List <IDataLoadComponent> { getFiles, adjustStagingAndMigrateToLive, archiveFiles }; return(new SingleJobExecution(components)); }
public void TestAllFilesAreArchived() { var directoryHelper = new TestDirectoryHelper(GetType()); directoryHelper.SetUp(); var forArchiving = directoryHelper.Directory.CreateSubdirectory("forArchiving"); var forLoading = directoryHelper.Directory.CreateSubdirectory("forLoading"); File.WriteAllText(Path.Combine(forLoading.FullName, "test.txt"), "test data"); var subDir = forLoading.CreateSubdirectory("subdir"); File.WriteAllText(Path.Combine(subDir.FullName, "subdir.txt"), "test data in subdir"); // test the hidden dir which the archiver should ignore var hiddenDir = forLoading.CreateSubdirectory(ArchiveFiles.HiddenFromArchiver); File.WriteAllText(Path.Combine(hiddenDir.FullName, "hidden.txt"), "I should not appear in the archive"); var archiveComponent = new ArchiveFiles(new HICLoadConfigurationFlags()); var dataLoadInfo = Mock.Of <IDataLoadInfo>(info => info.ID == 1); var LoadDirectory = Mock.Of <ILoadDirectory>(d => d.ForArchiving == forArchiving && d.ForLoading == forLoading); var job = Mock.Of <IDataLoadJob>(j => j.DataLoadInfo == dataLoadInfo); job.LoadDirectory = LoadDirectory; try { archiveComponent.Run(job, new GracefulCancellationToken()); // first we expect a file in forArchiving called 1.zip var zipFilename = Path.Combine(forArchiving.FullName, "1.zip"); Assert.True(File.Exists(zipFilename)); // there should be two entries using (var archive = ZipFile.Open(zipFilename, ZipArchiveMode.Read)) { Assert.AreEqual(2, archive.Entries.Count, "There should be two entries in this archive: one from the root and one from the subdirectory"); Assert.IsTrue(archive.Entries.Any(entry => entry.FullName.Equals(@"subdir/subdir.txt"))); Assert.IsTrue(archive.Entries.Any(entry => entry.FullName.Equals(@"test.txt"))); } } finally { directoryHelper.TearDown(); } }
/// <summary> /// Populate all the archive entries from the game archive folder /// </summary> static private void _Populate() { _archiveFilesVersions = new Dictionary <string, ArchiveFileVersions>(); if (Directory.Exists(Directories.ProjectGameArchivesFolder)) { _archiveFiles = new ArchiveFiles(); bool __mutextCreated = false; Mutex __mutex = new Mutex(true, "LeagueSharpArchives", out __mutextCreated); // Wait until it is safe to enter. __mutex.WaitOne(); _archiveFiles.DeSerialize(_dbPath + ".list"); _archiveFileEntries.DeSerialize(_dbPath + ".dat"); if (__mutextCreated) { List <string> rafFilePaths = _GetArchiveFiles(Directories.ProjectGameArchivesFolder); ArchivesCount = rafFilePaths.Count; bool __modified = false; foreach (string path in rafFilePaths) { if (!_archiveFiles.Contains(path.ToLowerInvariant())) { __modified = true; ArchiveReader raf = new ArchiveReader(path); _archiveFileEntries.AddRange(raf.FileDictFull.Values); _archiveFiles.Add(path.ToLowerInvariant()); } } if (__modified) { _archiveFiles.Serialize(_dbPath + ".list"); _archiveFileEntries.Serialize(_dbPath + ".dat"); } } __mutex.ReleaseMutex(); for (int __i = 0; __i < _archiveFileEntries.Count; __i++) { string __filename = _archiveFileEntries[__i].FileName.ToLowerInvariant(); if (!_archiveFilesVersions.ContainsKey(__filename)) { _archiveFilesVersions.Add(__filename, new ArchiveFileVersions()); } _archiveFilesVersions[__filename].Add(__i); } } }
public ResourceManager(string archiveDirectory) { resourceRootDir = archiveDirectory; if (!Directory.Exists(archiveDirectory)) { throw new System.Exception("Resource manager must be passed an archive directory."); } List <string> volFilenames = GetFilesFromDirectory("*.vol"); foreach (string volFilename in volFilenames) { ArchiveFiles.Add(new VolFile(Path.Combine(archiveDirectory, volFilename))); } List <string> clmFilenames = GetFilesFromDirectory("*.clm"); foreach (string clmFilename in clmFilenames) { ArchiveFiles.Add(new ClmFile(Path.Combine(archiveDirectory, clmFilename))); } }
/// <summary> /// Opens the archive explorer /// </summary> /// <returns>The task</returns> public async Task OpenAsync() { var attr = GameMode.GetAttribute <UbiArtGameModeInfoAttribute>(); var settings = UbiArtSettings.GetDefaultSettings(attr.Game, attr.Platform); // Show the archive explorer await RCPServices.UI.ShowArchiveExplorerAsync(new UbiArtIPKArchiveExplorerDataManager(settings), ArchiveFiles.Where(x => x.FileExists)); }
/// <summary> /// Populate all the archive entries from the game archive folder /// </summary> static private void _Populate() { _archiveFilesVersions = new Dictionary <string, ArchiveFileVersions>(); if (Directory.Exists(Directories.ProjectGameArchivesFolder)) { _archiveFiles = new ArchiveFiles(); bool __mutextCreated = false; Mutex __mutex = new Mutex(true, "LeagueSharpArchives", out __mutextCreated); // Wait until it is safe to enter. __mutex.WaitOne(); Directory.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "LeagueSharp", "GameArchiveDb"), true); Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "LeagueSharp", "GameArchiveDb")); _archiveFiles.DeSerialize(_dbPath + ".list"); _archiveFileEntries.DeSerialize(_dbPath + ".dat"); if (__mutextCreated) { List <string> rafFilePaths = _GetArchiveFiles(Directories.ProjectGameArchivesFolder); ArchivesCount = rafFilePaths.Count; bool __modified = false; foreach (string path in rafFilePaths) { if (!_archiveFiles.Contains(path.ToLowerInvariant())) { __modified = true; ArchiveReader raf = new ArchiveReader(path); _archiveFileEntries.AddRange(raf.FileDictFull.Values); _archiveFiles.Add(path.ToLowerInvariant()); } } foreach (string path in _archiveFiles) { if (!rafFilePaths.Contains(path.ToLowerInvariant())) { __modified = true; foreach (ArchiveFileListEntry entry in _archiveFileEntries.ToArray()) { if (!File.Exists(entry.RAFFileDataPath)) { _archiveFileEntries.Remove(entry); } } _archiveFiles.Remove(path.ToLowerInvariant()); } } if (__modified) { _archiveFiles.Serialize(_dbPath + ".list"); _archiveFileEntries.Serialize(_dbPath + ".dat"); } } __mutex.ReleaseMutex(); for (int __i = 0; __i < _archiveFileEntries.Count; __i++) { string __filename = _archiveFileEntries[__i].FileName.ToLowerInvariant(); if (!_archiveFilesVersions.ContainsKey(__filename)) { _archiveFilesVersions.Add(__filename, new ArchiveFileVersions()); } _archiveFilesVersions[__filename].Add(__i); } } }