private string GetFiles() { var tempPath = ConfigDirectoryPath; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } Directory.CreateDirectory(tempPath); var service = new CompanyServiceClient(); var stream = service.GetCompanyFiles(Company.Id, "assets"); var zipFile = Path.Combine(tempPath, "out.zip"); using (Stream file = File.OpenWrite(zipFile)) { CopyStream(stream, file); } using (var unzip = new Unzip(zipFile)) { unzip.ExtractToDirectory(tempPath); } File.Delete(zipFile); CreateConfigFile(Path.Combine(tempPath, "settings.json"), s => s.IsClientSetting); CreateConfigFile(Path.Combine(tempPath, "allSettings.json"), s => true); return(tempPath); }
private void ExtractToDirectory(string zipFilePath, string directory) { using (var unzip = Unzip.Open(zipFilePath, FileAccess.Read)) { var zipEntries = unzip.ReadCentralDir(); foreach (var entry in zipEntries) { if (_unzipCancellationToken.IsCancellationRequested) { _unzipCancellationToken.ThrowIfCancellationRequested(); } var filePath = Path.Combine(directory, entry.FilenameInZip); var fileDirectory = Path.GetDirectoryName(filePath); if (null == fileDirectory) { throw new InvalidOperationException("null == fileDirectory"); } if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } unzip.ExtractFile(entry, filePath); } } }
public void LogsErrorIfReadOnlyFileCannotBeOverwitten() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file1 = testEnvironment.CreateFile(source, "D6DFD219DACE48F8B86EFCDF98433333.txt", "file1"); new FileInfo(file1.Path).IsReadOnly = true; TransientZipArchive zipArchive = TransientZipArchive.Create(source, destination); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(source.Path), OverwriteReadOnlyFiles = false, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain($"D6DFD219DACE48F8B86EFCDF98433333.txt{ (NativeMethodsShared.IsMono ? "\"" : "'") } is denied", () => _mockEngine.Log); } }
public void CanOverwriteReadOnlyFile() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file1 = testEnvironment.CreateFile(source, "638AF4AE88A146E09CB69FE1CA7083DC.txt", "file1"); new FileInfo(file1.Path).IsReadOnly = true; TransientZipArchive zipArchive = TransientZipArchive.Create(source, destination); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(source.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("638AF4AE88A146E09CB69FE1CA7083DC", () => _mockEngine.Log); } }
private void FlashFirmwareBetaToolStripMenuItem_Click(object sender, EventArgs e) { string[] paths = Directory.GetFiles(@"C:\adb\MIFlash", "XiaoMiFlash.exe"); string[] paths2 = Directory.GetFiles(@"C:\adb\MIFlash", "MiFlash20181115.zip"); if (paths.Length > 0) { try { var proc = new System.Diagnostics.Process(); proc = Process.Start(@"C:\adb\MIFlash\XiaoMiFlash.exe", ""); } catch { MessageBox.Show("XiaoMiFlash closed...", "Mi Flash", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (paths2.Length > 0) { Unzip.Unzippy(@"MIFlash\MiFlash20181115.zip", @"MIFlash", true); string[] zipfile = Directory.GetFiles(@"C:\adb\MIFlash\", "*.zip"); foreach (string f in zipfile) { File.Delete(f); } MessageBox.Show("Mi Flash extracted! Click again this option!", "Mi Flash", MessageBoxButtons.OK, MessageBoxIcon.Error); visual_reLoad(); } MessageBox.Show("Error on loading XiaoMiFlash, seems to be missing... You can download it on Download Mi Flash", "Mi Flash", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public virtual IDictionary <string, string> ToDictionary() { return(new Dictionary <string, string> { { "method", Method.ToString() }, { "raw", Raw.ToLowerString() }, { "fileName", FileName ?? "" }, { "fileSize", FileSize.ToString(CultureInfo.InvariantCulture) }, { "batchId", BatchId ?? "" }, { "batchLast", BatchLast.ToLowerString() }, { "canResume", CanResume.ToLowerString() }, { "startOver", StartOver.ToLowerString() }, { "unzip", Unzip.ToLowerString() }, { "tool", Tool }, { "title", Title ?? "" }, { "details", Details ?? "" }, { "sendGuid", SendGuid ?? "" }, { "threadCount", Convert.ToString(ThreadCount) }, { "overwrite", Overwrite.ToLowerString() }, { "isSend", IsSend.ToLowerString() }, { "responseFormat", ResponseFormat }, { "notify", Notify.ToLowerString() }, { "clientCreatedDateUTC", ClientCreatedDateUtc.HasValue ? ClientCreatedDateUtc.Value.ToString("u"): "" }, { "clientModifiedDateUTC", ClientModifiedDateUtc.HasValue ? ClientModifiedDateUtc.Value.ToString("u"): "" }, { "baseFileId", BaseFileId } }); }
public void CanUnzip_WithIncludeAndExcludeFilter() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFolder sub = source.CreateDirectory("sub"); testEnvironment.CreateFile(source, "file1.js", "file1"); testEnvironment.CreateFile(source, "file1.js.map", "file2"); testEnvironment.CreateFile(source, "file2.js", "file3"); testEnvironment.CreateFile(source, "readme.txt", "file4"); testEnvironment.CreateFile(sub, "subfile.js", "File5"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) }, Include = "*.js", Exclude = "*.js.map;sub\\*.js" }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "file1.js"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "file1.js.map"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "file2.js"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "readme.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "sub", "subfile.js"), () => _mockEngine.Log); } }
public void CanUnzip() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "BE78A17D30144B549D21F71D5C633F7D.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "A04FF4B88DF14860B7C73A8E75A4FB76.txt"), () => _mockEngine.Log); } }
public void LogsErrorIfExcludeContainsPropertyReferences() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) }, Exclude = "$(Include)" }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3938", () => _mockEngine.Log); } }
public void CanUnzip_ExplicitDirectoryEntries() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientTestFolder emptyDir = source.CreateDirectory("emptyDir"); TransientTestFolder subDir = source.CreateDirectory("subDir"); subDir.CreateFile("F83E9633685494E53BEF3794EDEEE6A6.txt", "file3"); subDir.CreateFile("21D6D4596067723B3AC5DF9A8B3CBFE7.txt", "file4"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "BE78A17D30144B549D21F71D5C633F7D.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "A04FF4B88DF14860B7C73A8E75A4FB76.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "subdir", "F83E9633685494E53BEF3794EDEEE6A6.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "subdir", "21D6D4596067723B3AC5DF9A8B3CBFE7.txt"), () => _mockEngine.Log); Directory.Exists(Path.Combine(destination.Path, "emptyDir")); } }
private async void DownloadProgressPlus() { this.download = tools.GetMissingAsset(Version); if (download.Length > 900) { assetDownloadPlus.StartDownload(); await Task.Factory.StartNew(() => { while (!assetDownloadPlus.GetEndDownload()) { Speed = assetDownloadPlus.Speed; Progress = assetDownloadPlus.Progress / 2; Thread.Sleep(2000); } }); Unzip unzip = new Unzip(); string Out = ""; unzip.UnZipFile(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncherDownload\Asset\Assets.zip", System.Directory.GetCurrentDirectory() + @"\.minecraft\assets\", out Out); Thread.Sleep(4000); } Console.WriteLine("pass"); tools.DownloadSourceInitialization(DownloadSource.MCBBSSource); Progress = 50; DuckEndDownload = 0; download = tools.GetMissingAsset(Version); EndDownload = tools.GetAllTheAsset(Version).Length - download.Length; for (int i = 0; i < Threads.Length; i++) { Threads[i] = Task.Run(DownloadProgress); // Threads[i].Start();//启动线程 } }
public async Task BeginInstall(ProgressCallback monitor, CancellationToken cancellationToken) { CommonInstaller.IsInstal = true; string installerName = Path.GetFileNameWithoutExtension(InstallerPath); string tempPath = string.Format("{0}\\{1}Temp", PathManager.TempDirectory, installerName); if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } Directory.CreateDirectory(tempPath); Unzip.UnZipFile(InstallerPath, tempPath); string mainJson = File.ReadAllText(tempPath + "\\install_profile.json"); JObject jObject = JObject.Parse(mainJson); if (jObject.ContainsKey("install") && jObject.ContainsKey("versionInfo")) { CommonInstaller commonInstaller = new CommonInstaller(InstallerPath, Options); await commonInstaller.BeginInstallFromJObject(monitor, cancellationToken, jObject, tempPath); } else if (jObject.ContainsKey("data") && jObject.ContainsKey("processors") && jObject.ContainsKey("libraries")) { DataProcessorsForgeInstaller forgeInstaller = new DataProcessorsForgeInstaller(InstallerPath, Options); await forgeInstaller.BeginInstallFromJObject(monitor, cancellationToken, jObject, tempPath); } else { throw new JsonException("JSON has no matching format"); } Directory.Delete(tempPath, true); File.Delete(InstallerPath); CommonInstaller.IsInstal = false; }
/// <summary> /// 对文件进解压 /// </summary> /// <param name="inPutFileName">输入流:需要解压的文件</param> /// <param name="outputFileName">输出流:解压状态</param> public static void UnFileZip(string inPutFileName, string outputFileName) { try { using (Stream file = new FileStream(inPutFileName, FileMode.Open, FileAccess.Read)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); //反序列为对应类型输出 var sbytes = (sbyte[])binaryFormatter.Deserialize(file); var list = (Dictionary <Byte, string>)binaryFormatter.Deserialize(file); Unzip unzip = new Unzip(); var cur = unzip.UnzIpBytes(list, sbytes); using (Stream output = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(output)) { writer.Write(cur); } } } } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } catch (SerializationException ex) { Console.WriteLine(ex.Message); } }
public static void Main(string[] args) { //i like like like java do you like a java string str = "as"; //获取字符出现频率统计表 Byte[] source = Encoding.UTF8.GetBytes(str); //重要的源数据 Console.WriteLine("原始长度:" + str.Length); CreatedHuffmanData huffmanCode = new CreatedHuffmanData(); //进行压缩,压缩数据存放在_huffmanData中 huffmanCode.CreHuffmanData(source); // for (int i = 0; i < huffmanCode.HuffmanData.Length; i++) // { // Console.WriteLine(huffmanCode.HuffmanData[i]); // } Console.WriteLine("解压"); Unzip unzip = new Unzip(); var zip = unzip.UnzIpBytes(huffmanCode.GetHuffmanCodeMap(), huffmanCode.HuffmanData); Console.WriteLine(zip); //FileZip("D:\\数据结构与算法\\树\\huffmanCode\\baseCode.txt","D:\\数据结构与算法\\树\\huffmanCode\\base.zip"); UnFileZip("D:\\数据结构与算法\\树\\huffmanCode\\base.zip", "D:\\数据结构与算法\\树\\huffmanCode\\bases.txt"); }
public Stream UnzipFile(string path, string fileNameinZip) { #if !EXCLUDE_JAVASCRIPT return(Unzip.Unzip(path, fileNameinZip)); #else return(null); #endif }
public async Task BuildAssetDownload(int NumThreads, string version) { _NumThreads = NumThreads; _version = version; if (!_disposed) { AllFile = new Tools().GetAllTheAsset(version).Length; _disposed = true; } if (FinishFile == AllFile) { return; } string Path = System.IO.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\Asset\"; if (File.Exists(Path + @"\ConsoleApp15.exe")) { process.StartInfo.FileName = "cmd.exe"; string Arguments = Path + @"ConsoleApp15.exe " + string.Format("{0} {1} {2}", version, NumThreads, System.Directory.GetCurrentDirectory()); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.CreateNoWindow = false; process.Start(); process.StandardInput.WriteLine(Arguments + "&exit"); process.StandardInput.AutoFlush = true; process.StandardInput.Close(); Thread thread = new Thread(Process_OutputDataReceived); thread.Start(); await Task.Run(() => { while (true) { if (FinishFile == AllFile) { return; } Thread.Sleep(2000); } }); } GacDownload gac = new GacDownload(); gac.Download(Path + "yq.zip", "http://www.baibaoblog.cn:81/Asset/Asset.zip"); while (gac.Complete != 1) { Thread.Sleep(500); } if (File.Exists(Path + "yq.zip")) { Unzip unzip = new Unzip(); string a = ""; unzip.UnZipFile(Path + "yq.zip", Path, out a); BuildAssetDownload(NumThreads, version); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: java.io.File prepareDirectory(java.io.File databaseDirectory) throws java.io.IOException internal virtual File PrepareDirectory(File databaseDirectory) { if (!databaseDirectory.exists() && !databaseDirectory.mkdirs()) { throw new IOException("Could not create directory " + databaseDirectory); } Unzip.unzip(this.GetType(), ResourceName, databaseDirectory); (new File(databaseDirectory, "debug.log")).delete(); // clear the log return(databaseDirectory); }
private void UnzipFile(byte[] data, string directory) { using (MemoryStream ms = new MemoryStream(data)) { using (var unzip = new Unzip(ms)) { unzip.ExtractToDirectory(directory); } } }
public byte[] CreateMidiFile() { var loader = File.ReadAllBytes(_filePath); switch (_extension) { case ".gp3": _gpfile = new GP3File(loader); _gpfile.readSong(); break; case ".gp4": _gpfile = new GP4File(loader); _gpfile.readSong(); break; case ".gp5": _gpfile = new GP5File(loader); _gpfile.readSong(); break; case ".gpx": _gpfile = new GP6File(loader); _gpfile.readSong(); _gpfile = _gpfile.self; //Replace with transferred GP5 file break; case ".gp": var stream = new MemoryStream(); using (var unzip = new Unzip(_filePath)) { unzip.Extract("Content/score.gpif", stream); stream.Position = 0; var sr = new StreamReader(stream); var gp7Xml = sr.ReadToEnd(); _gpfile = new GP7File(gp7Xml); _gpfile.readSong(); _gpfile = _gpfile.self; //Replace with transferred GP5 file } break; default: Logger.Error("Unknown File Format"); break; } Logger.Debug("Done"); var song = new Native.Format(_gpfile); return(song.ToMidi().createBytes().ToArray()); }
public void LogsErrorIfDirectoryCannotBeCreated() { Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(String.Empty) }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3931", () => _mockEngine.Log); }
public static Task DownloadSdk(GitOptions options) { return(Task.Run(async() => { var url = options.GitUrl + "/archive/development.zip"; var folderPath = options.RootFolder; var fileName = options.FileName.Replace(".zip", "") + "-development"; string zipPath, filePath; //if (!IsLinux) //{ zipPath = string.Format("{0}\\{1}", folderPath, fileName); filePath = string.Format("{0}.zip", zipPath); //} if (options.ReplaceExisting) { if (File.Exists(filePath)) { File.Delete(filePath); } if (Directory.Exists(zipPath)) { Directory.Delete(zipPath, true); } } using (var client = new HttpClient()) { var result = await client.GetAsync(url); result.EnsureSuccessStatusCode(); using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { await result.Content.CopyToAsync(fileStream); fileStream.Close(); } } if (File.Exists(filePath)) { var unzip = new Unzip(filePath); unzip.ExtractToDirectory(folderPath); } })); }
private static void ListFiles(Unzip unzip) { var tab = unzip.Entries.Any(e => e.IsDirectory) ? "\t" : string.Empty; foreach (var entry in unzip.Entries.OrderBy(e => e.Name)) { if (entry.IsFile) { //Debug.Log(tab + entry.Name+": "+ entry.CompressedSize + " -> "+ entry.OriginalSize); continue; } //Debug.Log(entry.Name); } //Debug.Log(""); }
/// <summary> /// 功能:解压zip格式的文件。 /// </summary> /// <param name="zipFile">压缩文件路径</param> /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param> /// <param name="error">出错信息</param> /// <returns>解压是否成功</returns> public static bool UnZipFile(string zipFile, string unZipDir, out string error) { error = ""; try { Unzip.UnzipFile(zipFile, unZipDir); } catch (Exception e) { error = e.Message; return(false); } return(true); /* * if (!File.Exists(zipFile)) * { * error = "file not exsist"; * return false; * } * * if (unZipDir.Length == 0) * unZipDir = Path.GetFullPath(zipFile) + Path.GetFileNameWithoutExtension(zipFile); * if (!unZipDir.EndsWith(@"\")) * unZipDir += @"\"; * if (!System.IO.Directory.Exists(unZipDir)) * System.IO.Directory.CreateDirectory(unZipDir); * try * { * Shell32.ShellClass sc = new Shell32.ShellClass(); * Shell32.Folder SrcFolder = sc.NameSpace(zipFile); * Shell32.Folder DestFolder = sc.NameSpace(unZipDir); * Shell32.FolderItems items = SrcFolder.Items(); * * DestFolder.CopyHere(items, 20); * } * catch (Exception ex) * { * error = ex.Message; * return false; * } * return true; */ }
public void LogsErrorIfSourceFileDoesNotExist() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), SourceFiles = new ITaskItem[] { new TaskItem(Path.Combine(testEnvironment.DefaultTestDirectory.Path, "foo.zip")), } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3932", () => _mockEngine.Log); } }
public void BeginInstall() { string gameRootPath = ((CommonInstallOptions)Options).GameRootPath; string tempPath = PathManager.TempDirectory + "\\CommonInstallerTemp"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } Directory.CreateDirectory(tempPath); Unzip.UnZipFile(InstallerPath, tempPath); string mainJson = File.ReadAllText(tempPath + "\\install_profile.json"); var jsonObj = JsonConvert.DeserializeObject <CommonJsonObj>(mainJson); var t = jsonObj.Install.Path.Split(':'); var libPackage = t[0]; var libName = t[1]; var libVersion = t[2]; string libPath = string.Format(@"{0}\libraries\{1}\{2}\{3}\{2}-{3}.jar", gameRootPath, libPackage.Replace(".", @"\"), libName, libVersion); string libDir = Path.GetDirectoryName(libPath); if (!Directory.Exists(libDir)) { Directory.CreateDirectory(libDir); } File.Copy(tempPath + '\\' + jsonObj.Install.FilePath, libPath, true); string newPath = PathManager.GetJsonPath(gameRootPath, jsonObj.Install.Target); string newDir = Path.GetDirectoryName(newPath); string jarPath = PathManager.GetJarPath(gameRootPath, jsonObj.Install.Target); if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); } File.WriteAllText(newPath, jsonObj.VersionInfo.ToString()); File.Copy(tempPath + '\\' + jsonObj.Install.FilePath, jarPath, true); Directory.Delete(tempPath, true); File.Delete(InstallerPath); }
private void unlockbootloader_Click(object sender, EventArgs e) { string[] paths = Directory.GetFiles(@"C:\adb\MIUnlock", "miflash_unlock.exe"); string[] paths2 = Directory.GetFiles(@"C:\adb\MIUnlock", "miflash_unlock-en-3.5.1128.45.zip"); if (paths.Length > 0) { try { var proc = new System.Diagnostics.Process(); proc = Process.Start(@"C:\adb\MIUnlock\miflash_unlock.exe", ""); } catch (Exception) { MessageBox.Show("Mi Unlock Closed...", "Mi Unlock", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (paths2.Length > 0) { Unzip.Unzippy(@"MIUnlock\miflash_unlock-en-3.5.1128.45.zip", @"MIUnlock", true); string[] zipfile = Directory.GetFiles(@"C:\adb\MIUnlock\", "*.zip"); foreach (string f in zipfile) { File.Delete(f); } MessageBox.Show("Mi Unlock extracted! Click again this option!", "Mi Unlock", MessageBoxButtons.OK, MessageBoxIcon.Error); visual_reLoad(); } MessageBox.Show("Error on loading Mi Unlock, seems to be missing... Please download it!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (System.IO.File.Exists(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") & System.IO.File.Exists(@"C:\Program Files\Google\Chrome\Application\chrome.exe") == true) { BrowserCheck.StartBrowser("MicrosoftEdge.exe", "https://c.mi.com/thread-1857937-1-1.html"); } else { BrowserCheck.StartBrowser("Chrome.exe", "https://c.mi.com/thread-1857937-1-1.html"); } }
public string DownloadData() { WebClient wc = new WebClient(); wc.DownloadFile(cmd, "Resource/subjectfile.zip"); using (var unzip = new Unzip("Resource/subjectfile.zip")) { string file = "error"; // list all files in the archive foreach (var fileName in unzip.FileNames) { file = fileName; } // extract single file to a specifie4d location unzip.Extract(file, "Resource/" + file); return(result = "Resource/" + file); } }
public void LogsErrorIfSourceFileCannotBeOpened() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file = testEnvironment.CreateFile("foo.txt", "foo"); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), SourceFiles = new ITaskItem[] { new TaskItem(file.Path), } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3933", () => _mockEngine.Log); } }
public void UnzipExecute() { string testDir = TaskUtility.TestDirectory; string zipFileName = Path.Combine(testDir, ZipTest.ZIP_FILE_NAME); if (!File.Exists(zipFileName)) { Assert.Ignore("Zip file \"{0}\" not found; first run test that creates it", zipFileName); } ZipTest zip = new ZipTest(); zip.ZipExecute(); Unzip task = new Unzip(); task.BuildEngine = new MockBuild(); task.ZipFileName = zipFileName; task.TargetDirectory = Path.Combine(testDir, @"Backup"); Assert.IsTrue(task.Execute(), "Execute Failed"); }
public static void Main(string[] args) { string str = "i like like like java do you like a java"; // string str = "aaa"; //重要的源数据 Console.WriteLine("原始长度:" + str.Length); CreatedHuffmanData huffmanCode = new CreatedHuffmanData(); huffmanCode.CreHuffmanData(str); for (int i = 0; i < huffmanCode.HuffmanData.Length; i++) { Console.WriteLine(huffmanCode.HuffmanData[i]); } Console.WriteLine("解压"); Unzip unzip = new Unzip(); var zip = unzip.Bytes(huffmanCode.GetHuffmanCodeMap(), huffmanCode.HuffmanData); Console.WriteLine(zip); }
public async Task BeginInstall(ProgressCallback callback, CancellationToken cancellationToken) { IsInstal = true; string installerName = Path.GetFileNameWithoutExtension(InstallerPath); string tempPath = string.Format("{0}\\{1}Temp", PathManager.TempDirectory, installerName); if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } Directory.CreateDirectory(tempPath); Unzip.UnZipFile(InstallerPath, tempPath); string mainJson = File.ReadAllText(tempPath + "\\install_profile.json"); JObject jObject = JObject.Parse(mainJson); await BeginInstallFromJObject(callback, cancellationToken, jObject, tempPath); Directory.Delete(tempPath, true); File.Delete(InstallerPath); IsInstal = false; }