private void ParseImportFiles(string[] files, bool isZip = true) { if (files.Length > 1) { MessageBox.Show("Only drag one zip file or folder!"); return; } string fileExt = Path.GetExtension(files[0]); if (fileExt.Equals(".zip") || fileExt.Equals(".7z")) { if (!isZip) { return; } CleanUnzipFolder(); UnZipper unZipper = new UnZipper(); unZipper.ZipFile = files[0]; unZipper.ItemList.Add("*.*"); unZipper.Destination = PathHelper.FolderTemp + "unzip" + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(files[0]) + Path.DirectorySeparatorChar; unZipper.Recurse = true; unZipper.UnZip(); LogHelper.Debug("Unzipping file..."); ParseImportFiles(new string[1] { PathHelper.FolderTemp + "unzip" + Path.DirectorySeparatorChar }); return; } else { string baseDirectory = files[0] + (!files[0].EndsWith(Path.DirectorySeparatorChar.ToString()) ? Path.DirectorySeparatorChar.ToString() : string.Empty); files = ValidateFiles(files); if (files != null) { if (files.Length > 0) { switch (_ModListType) { case (ModListType.CharacterSlots): ProcessCharacterSlotModFiles(files, baseDirectory); break; case (ModListType.CharacterGeneral): ProcessCharacterGeneralModFiles(files, baseDirectory); break; case (ModListType.Stage): ProcessStageModFiles(files, baseDirectory); break; case (ModListType.General): ProcessGeneralModFiles(files, baseDirectory); break; } } } } }
/// <summary> /// Unzips file at provided in path to provided out path /// </summary> /// <param name="inPath">Path of the .zip to be unpacked</param> /// <param name="outDirectory">Directory to unpack .zip to</param> /// <returns></returns> public static bool Unpack(string inPath, string outDirectory) { try { string filePath = string.Format(@"{0}/{1}", outDirectory, Path.GetFileNameWithoutExtension(inPath)); if (File.Exists(filePath)) { File.Delete(filePath); } UnZipper uz = new UnZipper(); uz.Destination = outDirectory; uz.ItemList.Add("**"); uz.ZipFile = inPath; uz.UnZip(); return(true); } catch (Exception ex) { Console.WriteLine("Zlib Exception Occured\n{0}", ex.Message); } return(false); }
/// <summary> /// Unzips file at provided in path to provided out path /// </summary> /// <param name="inPath">Path of the .zip to be unpacked</param> /// <param name="outDirectory">Directory to unpack .zip to</param> /// <returns></returns> public static bool Unpack(string inPath, string outDirectory) { try { string filePath = string.Format(@"{0}/{1}", outDirectory, Path.GetFileNameWithoutExtension(inPath)); if (File.Exists(filePath)) { File.Delete(filePath); } UnZipper uz = new UnZipper(); uz.Destination = outDirectory; uz.ItemList.Add("**"); uz.ZipFile = inPath; uz.UnZip(); return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Zlib Exception Occured", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } return(false); }
public void TestTheUnzipper_ShouldNotThrowException() { var unzipper = new UnZipper(MockFileSystem); unzipper.UnZip(@"D:\features\Pickles.Examples\BaseDhtmlFiles.zip", @"d:\output", "BaseDhtmlFiles"); }