/// <summary> /// Extract zip file to a folder /// </summary> /// <param name="zipInputFullPath">input e.g: /path/file.zip</param> /// <param name="storeZipFolderFullPath">output e.g. /folder/</param> /// <returns></returns> public bool ExtractZip(string zipInputFullPath, string storeZipFolderFullPath) { if (!File.Exists(zipInputFullPath)) { return(false); } // todo: implement this comma separated list >> string matchExtensions = "*" // Ensures that the last character on the extraction path // is the directory separator char. // Without this, a malicious zip file could try to traverse outside of the expected // extraction path. storeZipFolderFullPath = PathHelper.AddBackslash(storeZipFolderFullPath); using (ZipArchive archive = ZipFile.OpenRead(zipInputFullPath)) { foreach (ZipArchiveEntry entry in archive.Entries) { // Gets the full path to ensure that relative segments are removed. string destinationPath = Path.GetFullPath(Path.Combine(storeZipFolderFullPath, entry.FullName)); // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that // are case-insensitive. if (destinationPath.StartsWith(storeZipFolderFullPath, StringComparison.Ordinal)) { entry.ExtractToFile(destinationPath); } } } return(true); }
private void PerformSavegameBackup(string trackedSavFile) { if (File.Exists(trackedSavFile)) { var hash = MD5Helper.GetMD5String(trackedSavFile); if (!_saveList.Exists(hs => hash == hs.Checksum)) { string locName = GenerateLocationName(hash); string backupBasePath = PathHelper.AddBackslash(_config.SaveBackupPath) + locName; string backupPath = backupBasePath + ".sav"; string screenCapturePath = backupBasePath + ".jpg"; HellbladeSaveItem hSaveItem = new HellbladeSaveItem() { SaveFilePath = backupPath, ScreenCaptureFilePath = screenCapturePath, CaptureTime = DateTime.Now, Checksum = hash, LocationName = locName }; _saveList.Add(hSaveItem); File.Copy(trackedSavFile, backupPath); GrabScreenCapture()?.Save(screenCapturePath, System.Drawing.Imaging.ImageFormat.Jpeg); SimpleLogger.Default.Info("New save location: {0}", hSaveItem); } } }
public async Task MergeJsonFiles_StackFromEnv() { var testDir = Path.Combine(new AppSettings().BaseDirectoryProject, "_test"); _hostStorage.FolderDelete(testDir); _hostStorage.CreateDirectory(testDir); await _hostStorage.WriteStreamAsync(new PlainTextFileHelper().StringToStream( "{\n \"app\": {\n " + " \"StorageFolder\": \"/data/test\",\n \"addSwagger\": \"true\" " + " }\n}\n"), Path.Combine(testDir, "appsettings.json")); await _hostStorage.WriteStreamAsync(new PlainTextFileHelper().StringToStream( "{\n \"app\": {\n \"addSwagger\": \"false\" " + " }\n}\n"), Path.Combine(testDir, "appsettings_ref_patch.json")); Environment.SetEnvironmentVariable("app__appsettingspath", Path.Combine(testDir, "appsettings_ref_patch.json")); var result = await SetupAppSettings.MergeJsonFiles(testDir); Assert.AreEqual(PathHelper.AddBackslash("/data/test"), result.StorageFolder); Assert.AreEqual(false, result.AddSwagger); Environment.SetEnvironmentVariable("app__appsettingspath", null); }
public string FilePathOverlayImage(string outputParentFullFilePathFolder, string sourceFilePath, AppSettingsPublishProfiles profile) { var result = PathHelper.AddBackslash(outputParentFullFilePathFolder) + FilePathOverlayImage(sourceFilePath, profile); return(result); }
public void FilePathOverlayImage_outputParentFullFilePathFolder() { var image = new OverlayImage(_selectorStorage, new AppSettings()).FilePathOverlayImage( string.Empty, "TesT.Jpg", new AppSettingsPublishProfiles()); Assert.AreEqual(PathHelper.AddBackslash(string.Empty) + "test.jpg", image); }
public void ConfigRead_AddBackslashTest() { var input = PathHelper.AddBackslash("2018"); var output = "2018" + Path.DirectorySeparatorChar.ToString(); Assert.AreEqual(input, output); input = PathHelper.AddBackslash("2018" + Path.DirectorySeparatorChar.ToString()); output = "2018" + Path.DirectorySeparatorChar.ToString(); Assert.AreEqual(input, output); }
public RenameServiceTest() { var provider = new ServiceCollection() .AddMemoryCache() .BuildServiceProvider(); var memoryCache = provider.GetService <IMemoryCache>(); var builder = new DbContextOptionsBuilder <ApplicationDbContext>(); builder.UseInMemoryDatabase(nameof(RenameServiceTest)); var options = builder.Options; var context = new ApplicationDbContext(options); _newImage = new CreateAnImage(); _appSettings = new AppSettings { StorageFolder = PathHelper.AddBackslash(_newImage.BasePath), ThumbnailTempFolder = _newImage.BasePath }; _query = new Query(context, _appSettings, null, new FakeIWebLogger(), memoryCache); if (_query.GetAllFiles("/").All(p => p.FileName != _newImage.FileName)) { _query.AddItem(new FileIndexItem { FileName = _newImage.FileName, ParentDirectory = "/", AddToDatabase = DateTime.UtcNow, }); } var iStorage = new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger()); var readMeta = new ReadMeta(iStorage, _appSettings, memoryCache); _iStorageSubPath = new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger()); var services = new ServiceCollection(); var selectorStorage = new FakeSelectorStorage(iStorage); //_sync = new Synchronize(_appSettings, _query, selectorStorage, new FakeIWebLogger()); }
public async Task UpdateAppSettings_StorageFolder() { var storage = new FakeIStorage(new List <string> { "test" }); Environment.SetEnvironmentVariable("app__storageFolder", string.Empty); var controller = new AppSettingsController(new AppSettings(), new FakeSelectorStorage(storage)); var actionResult = await controller.UpdateAppSettings(new AppSettingsTransferObject { Verbose = true, StorageFolder = "test" }) as JsonResult; var result = actionResult.Value as AppSettings; Assert.IsTrue(result.Verbose); Assert.AreEqual(PathHelper.AddBackslash("test"), result.StorageFolder); }
public async Task MergeJsonFiles_DefaultFile() { var testDir = Path.Combine(new AppSettings().BaseDirectoryProject, "_test"); if (_hostStorage.ExistFolder(testDir)) { _hostStorage.FolderDelete(testDir); } _hostStorage.CreateDirectory(testDir); await _hostStorage.WriteStreamAsync(new PlainTextFileHelper().StringToStream( "{\n \"app\": {\n " + " \"StorageFolder\": \"/data/test\"\n " + " }\n}\n"), Path.Combine(testDir, "appsettings.json")); var result = await SetupAppSettings.MergeJsonFiles(testDir); Assert.AreEqual(PathHelper.AddBackslash("/data/test"), result.StorageFolder); }
public Dictionary <string, bool> CopyContent( AppSettingsPublishProfiles profile, string outputParentFullFilePathFolder) { _toCreateSubfolder.Create(profile, outputParentFullFilePathFolder); var parentFolder = PathHelper.AddBackslash( _appSettings.GenerateSlug(profile.Folder, true)); var copyResult = new Dictionary <string, bool>(); var files = _hostStorage.GetAllFilesInDirectory(GetContentFolder()).ToList(); foreach (var file in files) { var subPath = parentFolder + Path.GetFileName(file); copyResult.Add(subPath, true); var fillFileOutputPath = Path.Combine(outputParentFullFilePathFolder, subPath); if (!_hostStorage.ExistFile(fillFileOutputPath)) { _hostStorage.FileCopy(file, fillFileOutputPath); } } return(copyResult); }
public static ProgramParameters Parse(params string[] args) { /* Default path where Hellblade data is stored */ string defaultPathBase = PathHelper.AddBackslash(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)) + @"HellbladeGame\Saved\SaveGames"; var prm = new ProgramParameters(); var tcfg = new HellbladeTrackingConfig() { SaveGamePath = defaultPathBase, SaveGameFilter = "*.sav", SaveBackupPath = defaultPathBase + "\\Backup", DefaultNameFormat = "hellblade_{0:yyMMdd_HHmmss}_{1:000}_{2}", HellbladeExecutablePath = "HellbladeGame-Win64-Shipping", TargetImageSize = null }; prm.Verbosity = 1; var optionSet = new OptionSet() { { "h|help", p => prm.ShowHelp = true }, { "f|format=", p => tcfg.DefaultNameFormat = p }, { "p|process-name=", p => tcfg.HellbladeExecutablePath = p }, { "o|output-path=", p => tcfg.SaveBackupPath = p }, { "i|input-path=", p => tcfg.SaveGamePath = p }, { "w|wildcard=", p => tcfg.SaveGameFilter = p }, { "s|image-size=", p => tcfg.TargetImageSize = ParseSize(p.ToString()) }, { "v|verbosity=", p => prm.Verbosity = int.Parse(p) } }; var positional = optionSet.Parse(args); prm.ProgramOptionsSet = optionSet; prm.TrackingConfig = tcfg; return(prm); }