Esempio n. 1
0
		private static bool UnpackFile(string APath, string BasePath) {
			try {
				using (BlubbZipInputStream s = new BlubbZipInputStream(File.OpenRead(APath))) {

					BlubbZipEntry theEntry;
					while ((theEntry = s.GetNextEntry()) != null) {
						string fileName = Path.Combine(BasePath, theEntry.Name);
						string directoryName = Path.GetDirectoryName(fileName);

						if (directoryName.Length > 0 && Directory.Exists(directoryName) == false) {
							Directory.CreateDirectory(directoryName);
						}
						if (theEntry.IsFile == true && File.Exists(fileName)) {
							File.Delete(fileName);
						}

						if (theEntry.IsFile == true)
							using (FileStream streamWriter = File.Create(fileName)) {

								int size = 2048;
								byte[] data = new byte[2048];
								while (true) {
									if ((size = s.Read(data, 0, data.Length)) == 0) {
										break;
									}
									streamWriter.Write(data, 0, size);
								}
							}

					}

				}
			} catch (Exception e) {
				System.Diagnostics.Debug.WriteLine(e);
				return false;
			}

			return true;
		}
Esempio n. 2
0
		private static bool UnpackFile(string APath, string BasePath) {
			try {
				using (BlubbZipInputStream s = new BlubbZipInputStream(File.OpenRead(APath))) {

					BlubbZipEntry theEntry;
					while ((theEntry = s.GetNextEntry()) != null) {
						string fileName = Path.Combine(BasePath, theEntry.Name);
						string directoryName = Path.GetDirectoryName(fileName);

						if (directoryName.Length > 0 && Directory.Exists(directoryName) == false)
							Directory.CreateDirectory(directoryName);
						if (theEntry.IsFile == true && File.Exists(fileName))
							File.Delete(fileName);

						if (theEntry.IsFile == true)
							using (FileStream streamWriter = File.Create(fileName)) {

								int size = 2048;
								byte[] data = new byte[2048];
								while (true) {
									if ((size = s.Read(data, 0, data.Length)) == 0)
										break;
									streamWriter.Write(data, 0, size);
								}
							}

					}

				}
			} catch (Exception e) {
				System.Diagnostics.Debug.WriteLine(e);
				System.Windows.Forms.MessageBox.Show("Failed to extract Patch \"" + Path.GetFileName(APath) + "\"!\nPlease inform an Administrator about this.", "Extract Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
				return false;
			}

			return true;
		}
Esempio n. 3
0
		public static Dictionary<string, Stream> ExtractBlubbZip(Stream blubbzipStream, string blubbzipPassword) {
			Dictionary<string, Stream> streams = new Dictionary<string, Stream>();

			BlubbZipInputStream zipStream = new BlubbZipInputStream(blubbzipStream);
			try {
				zipStream.Password = blubbzipPassword;

				BlubbZipEntry entry;
				byte[] buff = new byte[65536];
				while ((entry = zipStream.GetNextEntry()) != null) {
					if (entry.IsDirectory) {
						while (zipStream.Read(buff, 0, buff.Length) > 0) { }
					} else {
						streams.Add(entry.Name, ExtractStream(zipStream, entry.Size));
					}
				}
			} finally {
				zipStream.Close();
			}

			return streams;
		}