// Code from https://github.com/icsharpcode/SharpZipLib/wiki/GZip-and-Tar-Samples private static void ExtractGZip(string pathTarget, string pathExtractTo) { // Use a 4K buffer. Any larger is a waste. byte[] dataBuffer = new byte[4096]; string pathTempExtractTo = Path.Combine(pathExtractTo, "temp"); using (Stream fs = new FileStream(pathTarget, FileMode.Open, FileAccess.Read)) { GZipInputStream gzip = new GZipInputStream(fs); using (GZipInputStream gzipStream = gzip) { // Extract for further extraction if (!Directory.Exists(pathTempExtractTo)) { DirectoryHandler.CreateDirectory(pathTempExtractTo); } using (FileStream fsOut = File.Create(Path.Combine(pathTempExtractTo, Path.GetFileNameWithoutExtension(pathTarget)))) { // Update progress text GUI.ProgressText = ProgressText + Path.GetFileName(fsOut.Name); StreamUtils.Copy(gzipStream, fsOut, dataBuffer); } } } // Extract the file again if needed (it should be needed) ExtractFile(Path.Combine(pathTempExtractTo, Path.GetFileNameWithoutExtension(pathTarget)), pathExtractTo, GUI); // Delete that file to prevent it from being extracted again DirectoryHandler.DestroyDirectory(pathTempExtractTo); }
// Your application's entry point. Here you can initialize your MVVM framework, DI // container, etc. private static void AppMain(Application app, string[] args) { // Delete any files marked for deletion before starting the app DirectoryHandler.DestroyMarkedForDeletion(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); ConfigHandler.LoadConfig(); var mainWindow = new MainWindow(); mainWindow.DataContext = new MainWindowViewModel(ConfigHandler.ConfigFile.Project.ID); app.Run(mainWindow); }
public static bool MoveDirectory(string pathTarget, string pathDestination, bool onlyChildren = false) { try { string pathNewDestination = pathDestination; if (!onlyChildren) { pathNewDestination = Path.Combine(pathNewDestination, Path.GetDirectoryName(pathTarget)); } foreach (string dir in Directory.EnumerateDirectories(pathTarget)) { //Directory.Move(dir, pathDestination); string nameDirectory = new DirectoryInfo(dir).Name; string pathTemp = Path.Combine(pathNewDestination, nameDirectory); Directory.CreateDirectory(pathTemp); DirectoryHandler.MoveDirectory(dir, pathTemp, true); } foreach (string file in Directory.EnumerateFiles(pathTarget)) { string nameFile = new FileInfo(file).Name; FileHandler.CopyFile(file, Path.Combine(pathNewDestination, nameFile)); } return(true); } catch (ArgumentException e) { Console.WriteLine("Error: " + e); return(false); } catch (IOException e) { Console.WriteLine("Error: " + e); return(false); } }