private static void UnZip(string zipFile, string folderPath) //flags above used to configure copy options //4 – Do not display a progress dialog box. //8 – Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. //16 – Respond with “Yes to All” for any dialog box that is displayed. //64 – Preserve undo information, if possible. //128 – Perform the operation on files only if a wildcard file name(*.*) is specified. //256 – Display a progress dialog box but do not show the file names. //512 – Do not confirm the creation of a new directory if the operation requires one to be created. //1024 – Do not display a user interface if an error occurs. //2048 – Version 4.71. Do not copy the security attributes of the file. //4096 – Only operate in the local directory.Do not operate recursively into subdirectories. //8192 – Version 5.0. Do not copy connected files as a group. Only copy the specified files. { if (!File.Exists(zipFile)) { throw new FileNotFoundException(); } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(folderPath); Shell32.Folder sourceFile = objShell.NameSpace(zipFile); foreach (var file in sourceFile.Items()) { destinationFolder.CopyHere(file, 16); } }
/// <summary> /// Helper method for performing uncompression /// </summary> /// <param name="compressedFileName">Compressed file name</param> /// <param name="destination">destination to be extracted</param> public static void UnCompressZip(string compressedFileName, string destination) { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFlder = sc.NameSpace(compressedFileName); Shell32.Folder DestFlder = sc.NameSpace(destination); Shell32.FolderItems items = SrcFlder.Items(); DestFlder.CopyHere(items, 10); }
/// <summary> /// 解压zip包 /// </summary> /// <param name="zipFile">压缩包目录</param> /// <param name="destFolder">解压文件的目标存放目录</param> private void UnZip(string zipFile, string destFolder) { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(zipFile); Shell32.Folder DestFolder = sc.NameSpace(destFolder); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); }
protected override void OnStartup(StartupEventArgs e) { DatabaseMigration dbMigration = new DatabaseMigration(); dbMigration.MigrationController(); Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName(current.ProcessName); if (processes.Count() > 1) { this.Shutdown(); } string fontFolderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts); Shell32.Folder fontFolder = GetShell32NameSpaceFolder(fontFolderPath); string base_folder = System.AppDomain.CurrentDomain.BaseDirectory + "in\\"; string segueUi = "segoeui.ttf"; string sarabunBold = "THSarabun Bold.ttf"; string sarabun = "THSarabun.ttf"; if (fontFolder != null) { string fontSegoeUI = base_folder + segueUi; if (!File.Exists(fontFolderPath + "\\" + segueUi)) { fontFolder.CopyHere(fontSegoeUI, 4); } string fontSarabunBold = base_folder + sarabunBold; if (!File.Exists(fontFolderPath + "\\" + sarabunBold)) { fontFolder.CopyHere(fontSarabunBold, 4); } string fontSarabun = base_folder + sarabun; if (!File.Exists(fontFolderPath + "\\" + sarabun)) { fontFolder.CopyHere(fontSarabun, 4); } } }
/* * * Metoda wyodrębniania plików z formatu .zip. */ public static void UnZip(string zipFile, string folderPath) { Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(folderPath); Shell32.Folder sourceFile = objShell.NameSpace(zipFile); foreach (var file in sourceFile.Items()) { destinationFolder.CopyHere(file, 4 | 16); } }
private void Btn_InstallFont_Click(object sender, RoutedEventArgs e) { try { Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder fontFolder = shell.NameSpace(0x14); fontFolder.CopyHere(pathToFolderInstaller + @"\segoe-mdl2-assets.ttf"); } catch { MessageBox.Show("у вас уже установлен шрифт"); } }
/// <summary> /// Zips the folder using the shell /// </summary> /// <remarks>Re-zipping a jar file using the .Net ZipFile class creates an invalid jar /// so we zip using the shell instead. /// The code is doing effectively the same as the PowerShell script used by the /// packaging project in the SonarQube Scanner for MSBuild: /// See https://github.com/SonarSource-VisualStudio/sonar-msbuild-runner/blob/master/PackagingProjects/CSharpPluginPayload/RepackageCSharpPlugin.ps1 /// </remarks> private static void ZipUsingShell(string sourceDir, string targetZipFilePath) { // The Folder.CopyHere method for Shell Objects allows configuration based on a combination of flags. // Docs here: https://msdn.microsoft.com/en-us/library/windows/desktop/bb787866(v=vs.85).aspx // The value below (1556) consists of // (4) - no progress dialog // (16) - respond with "yes to all" to any dialog box // (512) - Do not confirm the creation of a new directory // (1024) - Do not display an UI in case of error const int copyFlags = 1556; const int copyPauseInMilliseconds = 500; // The file must have a ".zip" extension for the shell code below to work string zipFilePath = targetZipFilePath + ".zip"; CreateEmptyZipFile(zipFilePath); Type shellAppType = Type.GetTypeFromProgID("Shell.Application"); Object app = Activator.CreateInstance(shellAppType); Shell32.Folder folder = shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, app, new object[] { zipFilePath }) as Shell32.Folder; foreach (string dir in Directory.GetDirectories(sourceDir)) { folder.CopyHere(dir, copyFlags); System.Threading.Thread.Sleep(copyPauseInMilliseconds); } foreach (string file in Directory.GetFiles(sourceDir, "*.*", SearchOption.TopDirectoryOnly)) { folder.CopyHere(file, copyFlags); System.Threading.Thread.Sleep(copyPauseInMilliseconds); } // Rename the file to the expected name File.Move(zipFilePath, targetZipFilePath); }
static void UnzipUpdateTo(string targerFolder) { try { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(System.IO.Path.Combine(Application.StartupPath, "Update.zip")); Shell32.Folder DestFolder = sc.NameSpace(targerFolder); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); } catch { return; } }
/// <summary> /// Main Program Start /// </summary> public MainWindow() { InitializeComponent(); Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder fontFolder = shell.NameSpace(0x14); fontFolder.CopyHere(@"Fonts/District Thin.ttf"); //Has no effect WindowClock.BeginAnimation(HeightProperty, Anims.StartAnimation); MouseDown += MainWindow_MouseDown; TimeUpdater(); Updater(true); }
/// <summary> /// Zip function calls Shell32, Interop.Shell32.dll is needed /// </summary> /// <param name="filesInFolder">Specify a folder containing the zip source files</param> /// <param name="zipFile">Specify the final zip file name, with ".zip" extension</param> public static void Compress(string filesInFolder, string zipFile) { if (filesInFolder == null || filesInFolder.Trim() == "") { return; } if (zipFile == null || zipFile.Trim() == "") { return; } if (!Directory.Exists(filesInFolder)) { return; } DirectoryEx.DeleteEmptyDirectory(filesInFolder); Shell32.ShellClass sh = new Shell32.ShellClass(); try { if (File.Exists(zipFile)) { File.Delete(zipFile); } //Create an empty zip file byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; FileStream fs = File.Create(zipFile); fs.Write(emptyzip, 0, emptyzip.Length); fs.Flush(); fs.Close(); Shell32.Folder srcFolder = sh.NameSpace(filesInFolder); Shell32.Folder destFolder = sh.NameSpace(zipFile); Shell32.FolderItems items = srcFolder.Items(); destFolder.CopyHere(items, SHFILEOPSTRUCT.FOF_SILENT | SHFILEOPSTRUCT.FOF_NOCONFIRMATION); while (items.Count != destFolder.Items().Count) { Thread.Sleep(50); } } finally { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(sh); } }
/// <summary> /// 功能:解压zip格式的文件。 /// </summary> /// <param name="zipFilePath">压缩文件路径</param> /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param> /// <param name="err">出错信息</param> /// <returns>解压是否成功</returns> public bool UnZipFile(string zipFilePath, string unZipDir, out string err) { err = ""; if (zipFilePath.Length == 0) { err = "压缩文件不能为空!"; return(false); } else if (!zipFilePath.EndsWith(".zip")) { err = "文件格式不正确!"; return(false); } else if (!File.Exists(zipFilePath)) { err = "压缩文件不存在!"; return(false); } //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 if (unZipDir.Length == 0) { unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath)); } if (!unZipDir.EndsWith("\\")) { unZipDir += "\\"; } if (!Directory.Exists(unZipDir)) { Directory.CreateDirectory(unZipDir); } try { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(zipFilePath); Shell32.Folder DestFolder = sc.NameSpace(unZipDir); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); } catch (Exception ex) { err = ex.Message; return(false); } return(true); }//解压结束
public static string ToZip(this DirectoryInfo d, string zipName = null, string zipExt = "zip", string basepath = null) { if (d == null) { throw new ArgumentNullException("Target Directory was null"); } if (zipName == null) { zipName = d.Name; } if (basepath == null) { basepath = Environment.CurrentDirectory; } /// Inbuilt ZIP functions don't give a Dynamics CRM readable archive, but System ZIP function does // https://www.codeproject.com/Articles/12064/Compress-Zip-files-with-Windows-Shell-API-and-C byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var path = Path.Combine(basepath, zipName + ".zip"); FileStream fs = File.Create(path); fs.Write(emptyzip, 0, emptyzip.Length); fs.Flush(); fs.Close(); fs = null; Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFlder = sc.NameSpace(d.FullName); Shell32.Folder DestFlder = sc.NameSpace(path); Shell32.FolderItems items = SrcFlder.Items(); DestFlder.CopyHere(items, 20); // TODO: FIXME: stop waiting for explorer to finish zipping do { System.Threading.Thread.Sleep(260); } while (new FileInfo(path).Length < 2 * 1024); if (zipExt != "zip") { File.Copy(path, Path.Combine(basepath, zipName + zipExt)); File.Delete(path); } return(Path.Combine(basepath, zipName + zipExt)); }
public void unzip() { listbox_info.Items.Add(" "); listbox_info.Items.Add("正在解压文件..."); try { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(filename); Shell32.Folder DestFolder = sc.NameSpace(Application.StartupPath + "\\"); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); listbox_info.Items.Add("解压完成..."); } catch (Exception) { listbox_info.Items.Add("解压失败..."); } }
public void ZipFolder(string sourceFolder, string dstFile) { byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; try { FileStream fs = File.Create(dstFile); fs.Write(emptyzip, 0, emptyzip.Length); fs.Flush(); fs.Close(); fs = null; Shell32.Shell sc = new Shell32.Shell(); Shell32.Folder SrcFlder = sc.NameSpace(sourceFolder); Shell32.Folder DestFlder = sc.NameSpace(dstFile); Shell32.FolderItems items = SrcFlder.Items(); DestFlder.CopyHere(items, 20); } catch { } }
//Read above for copy instructions private static void Copy(string startFile, string folderPath) { if (!File.Exists(startFile)) { throw new FileNotFoundException(); } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(folderPath); Shell32.Folder sourceFile = objShell.NameSpace(startFile); foreach (var file in sourceFile.Items()) { destinationFolder.CopyHere(file, 16); } }
/// <summary> /// From http://www.fluxbytes.com/csharp/unzipping-files-using-shell32-in-c/ but with /// args packed in object array so can be called from new STA Thread in UnZipFromMTAThread(). /// </summary> /// <param name="param">object array containing: [string zipFile, string destinationFolderPath]</param> private static void UnZip(string zipFile, string folderPath) { if (!File.Exists(zipFile)) { throw new FileNotFoundException(); } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(folderPath); Shell32.Folder sourceFile = objShell.NameSpace(zipFile); Shell32.FolderItems items = sourceFile.Items(); // Flags are: No progress displayed, Respond with 'Yes to All' for any dialog, no UI on error // I added 1024 although not sure it's relevant with Zip files. // See https://msdn.microsoft.com/en-us/library/windows/desktop/bb787866%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 destinationFolder.CopyHere(items, 4 | 16 | 1024); }
private static void ExtractFireBirdFiles(string zipFile) { string zipFileExtractionPath = Path.Combine(Application.StartupPath, Path.GetFileNameWithoutExtension(zipFile)); Utility.EnsureDirectory(zipFileExtractionPath); Shell32.ShellClass shellClass = new Shell32.ShellClass(); Shell32.Folder srcFolder = shellClass.NameSpace(zipFile); Shell32.Folder destFolder = shellClass.NameSpace(zipFileExtractionPath); destFolder.CopyHere(srcFolder.Items(), 16 | 256 | 512); File.Delete(zipFile); string destinationPath = Path.Combine(Application.StartupPath, "FirebirdSql.Data.FirebirdClient.dll"); File.Delete(destinationPath); File.Move(Path.Combine(zipFileExtractionPath, "FirebirdSql.Data.FirebirdClient.dll"), destinationPath); string basePath = Path.Combine(zipFileExtractionPath, "x86"); if (IntPtr.Size == 8) { basePath = Path.Combine(zipFileExtractionPath, "x64"); } string[] remainingFiles = new string[] { "fbembed.dll", "icudt30.dll", "icuin30.dll", "icuuc30.dll", "ib_util.dll", "firebird.conf", "firebird.msg" }; foreach (string file in remainingFiles) { string fileToMove = Path.Combine(basePath, file); destinationPath = Path.Combine(Application.StartupPath, file); File.Delete(destinationPath); File.Move(fileToMove, destinationPath); } Utility.DeleteDirectory(new DirectoryInfo(zipFileExtractionPath)); }
private bool UnZip(string zipFile, string folderPath) { if (!File.Exists(zipFile)) { throw new FileNotFoundException(); } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(folderPath); Shell32.Folder sourceFile = objShell.NameSpace(zipFile); foreach (var file in sourceFile.Items()) { destinationFolder.CopyHere(file, 4 | 16); } return(true); }
/// <summary> /// Unzips a file in given path, if it is a .zip file. /// Room for improvement - implementing RAR and 7z support. /// </summary> private void UnZip(string filePath) { if (File.Exists(filePath) && filePath.Substring(filePath.LastIndexOf('.')) == ".zip") { try { if (c.SubElText("Main", "FileProcessingOutputs") == "1") { o.Output(c.SubElText("Messages", "UnzipingFile") + filePath); } Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(filePath.Substring(0, filePath.LastIndexOf('\\') + 1)); Shell32.Folder sourceFile = objShell.NameSpace(filePath); // Change to destinationFolder.CopyHere(zipFile, 4 | 16) if you don't want to see untipping windows appearing foreach (var zipFile in sourceFile.Items()) { destinationFolder.CopyHere(zipFile, 16); } } catch (Exception e) { o.Output(c.SubElText("Messages", "UnZipingFileError") + filePath, e); } } }
private static void UnzipFileToFolderWindows(string zipFilePath, string destinationFolder) { const bool showProgress = false; const bool yesToAll = true; Shell32.Folder fromFolder = GetShell32NameSpace(zipFilePath); Directory.CreateDirectory(destinationFolder); Shell32.Folder toFolder = GetShell32NameSpace(destinationFolder); Shell32.FolderItems sourceFolderItems = fromFolder.Items(); Shell32.FolderItems itemsToExtract; //if the zip file contains a single directory, extract that directory's contents if ((sourceFolderItems.Count == 1) && (sourceFolderItems.Item(0).GetFolder is Shell32.Folder)) { Shell32.FolderItem rootItem = sourceFolderItems.Item(0); itemsToExtract = ((Shell32.Folder)rootItem.GetFolder).Items(); } else { itemsToExtract = sourceFolderItems; } int options = 0; if (!showProgress) { options += 4; } if (yesToAll) { options += 16; } toFolder.CopyHere(itemsToExtract, options); }
private static void UnzipFileToFolderWindows(string zipFilePath, string destionationFolder) { const bool showProgress = false; const bool yesToAll = true; Shell32.Folder sourceFolder = GetShell32NameSpace(zipFilePath); Directory.CreateDirectory(destionationFolder); Shell32.Folder destinationFolder = GetShell32NameSpace(destionationFolder); Shell32.FolderItems sourceFolderItems = sourceFolder.Items(); Shell32.FolderItem rootItem = sourceFolderItems.Item(0); int options = 0; if (!showProgress) { options += 4; } if (yesToAll) { options += 16; } destinationFolder.CopyHere(((Shell32.Folder)rootItem.GetFolder).Items(), options); }
public static void ZipFolder(string sourceFolder, string zipFile) { if (!System.IO.Directory.Exists(sourceFolder)) { throw new ArgumentException("sourceDirectory"); } byte[] zipHeader = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; using (System.IO.FileStream fs = System.IO.File.Create(zipFile)) fs.Write(zipHeader, 0, zipHeader.Length); Type shelltype = Type.GetTypeFromProgID("Shell.Application"); object shell = Activator.CreateInstance(shelltype); Shell32.Folder source = (Shell32.Folder)shelltype.InvokeMember("NameSpace", BindingFlags.InvokeMethod, null, shell, new object[1] { sourceFolder }); Shell32.Folder destination = (Shell32.Folder)shelltype.InvokeMember("NameSpace", BindingFlags.InvokeMethod, null, shell, new object[1] { zipFile }); destination.CopyHere(source.Items(), 0x14); }
static void Main(string[] args) { System.Console.WriteLine("The program has started."); if (args.Length == 3) { url = args[0]; username = args[1]; password = args[2]; } else if (debug == false) { url = "http://www.stuntyleeg.com/"; username = "******"; password = "******"; uploadzip uploadZip1 = new uploadzip(); uploadZip1.Filename = "C:\\Documents and Settings\\username\\My Documents\\BloodBowl\\Match_2010-07-13_20-12-45.zip"; uploadZip1.Password = password; uploadZip1.Url = url; uploadZip1.Username = username; uploadZip1.Page = page; uploadZip1.start(); Console.ReadKey(true); Environment.Exit(1); } else { System.Console.WriteLine("This program accepts 3 arguments: url, username, and password."); System.Console.WriteLine("Please use the following example and follow it as closely as possible."); System.Console.WriteLine("OBBLMCyUploader.exe http://www.example.com/ \"user name\" \"this ismy_password\""); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); Environment.Exit(1); } string mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string bbdir = (Directory.Exists(mydocs + "\\BloodBowlLegendary\\")) ? mydocs + "\\BloodBowlLegendary\\" : mydocs + "\\BloodBowl\\"; string matchreport = bbdir; string replay = bbdir + "Saves\\Replays\\"; string zipfile = bbdir; FileSystemWatcher sw_replay = new FileSystemWatcher(); Console.WriteLine("The replay folder is being monitored."); sw_replay.Path = replay; sw_replay.Filter = "Replay_*.db"; sw_replay.Created += new FileSystemEventHandler(OnChanged); sw_replay.EnableRaisingEvents = true; while (newfile == null) { } sw_replay.EnableRaisingEvents = false; replay = newfile.FullPath; zipfile += "Match_" + newfile.Name.Substring(7, newfile.Name.Length - 7 - 3) + ".zip";//-7 for Replay_ and -3 for .db //Replay_2010-07-03_17-47-21.db newfile = null; FileSystemWatcher sw_matchreport = new FileSystemWatcher(); System.Console.WriteLine("The match report folder is being monitored."); sw_matchreport.Path = matchreport; sw_matchreport.Filter = "MatchReport.sqlite"; sw_matchreport.Changed += new FileSystemEventHandler(OnChanged); sw_matchreport.EnableRaisingEvents = true; while (newfile == null) { } sw_matchreport.EnableRaisingEvents = false; matchreport += "MatchReport.sqlite"; Shell32.ShellClass sc = new Shell32.ShellClass(); if (createzip(zipfile)) { Shell32.Folder DestFlder = sc.NameSpace(zipfile); DestFlder.CopyHere(matchreport); checkStatus(1, DestFlder); DestFlder.CopyHere(replay); checkStatus(2, DestFlder); } uploadzip uploadZip = new uploadzip(); uploadZip.Filename = zipfile; uploadZip.Password = password; uploadZip.Url = url; uploadZip.Page = page; uploadZip.Username = username; uploadZip.start(); Console.WriteLine("The program has finished."); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); }
private async void downloadAndInstallSets() { // TODO: Show progression using a "Progress Dialog" control and : // https://github.com/100GPing100/LoadingIndicators.WPF // Preventing infinite loop. if (downloading) { return; } downloading = true; this.lblDownloading.Visibility = Visibility.Visible; var tempName = "ItemSets.zip"; var savePath = LoL_item_sets.Properties.Settings.Default.Save_Folder + @"\" + tempName; // Download the .zip archive with the item sets this.lblDownloading.Content = "Downloading archive ..."; try { using (var client = new WebClient()) { client.DownloadFile("https://lol-item-sets-generator.org/downloads/sets-from-app", savePath); } } catch (WebException e) { Trace.TraceError(e.Message); await this.ShowMessageAsync("Error", "Error when downloading the file to " + savePath + ". Either the website appears to be down or your sets location is incorrect."); this.lblDownloading.Visibility = Visibility.Hidden; downloading = false; return; } catch (Exception e) { Trace.TraceError(e.Message); await this.ShowMessageAsync("Error", "Error when downloading the file to " + savePath + ". Be sure to run the application as administrator or reconfigure the item sets path."); this.lblDownloading.Visibility = Visibility.Hidden; downloading = false; return; } // Delete all the directories => delete the previous item sets this.lblDownloading.Content = "Deleting sets ..."; foreach (System.IO.DirectoryInfo dir in new System.IO.DirectoryInfo(LoL_item_sets.Properties.Settings.Default.Save_Folder).GetDirectories()) { dir.Delete(true); } // Unzipping the .zip archive this.lblDownloading.Content = "Unzipping sets ..."; Shell32.Folder destinationFolder = GetShell32NameSpaceFolder(LoL_item_sets.Properties.Settings.Default.Save_Folder); Shell32.Folder sourceFile = GetShell32NameSpaceFolder(savePath); if (sourceFile == null) { Trace.TraceError("The downloaded .zip archive could not be found."); await this.ShowMessageAsync("Error", "Error when unzipping the file. The downloaded .zip archive could not be found."); this.lblDownloading.Visibility = Visibility.Hidden; downloading = false; return; } if (sourceFile.Items().Item(0)?.Name != "ItemSets") { Trace.TraceError("The 'ItemSets' folder could not be found in the .zip archive."); await this.ShowMessageAsync("Error", "Error when unzipping the file. The 'ItemSets' folder could not be found in the .zip archive."); System.IO.File.Delete(savePath); this.lblDownloading.Visibility = Visibility.Hidden; downloading = false; return; } var items = GetShell32NameSpaceFolder(sourceFile.Items().Item(0).Path).Items(); for (int i = 0; i < items.Count; i++) { var file = items.Item(i); this.lblDownloading.Content = "Unzipping '" + items.Item(i).Name + "' ..."; destinationFolder.CopyHere(file, 4 | 16 | 64); } // Deleting the .zip archive this.lblDownloading.Content = "Deleting archive ..."; System.IO.File.Delete(savePath); this.lblDownloading.Content = "Done !"; downloading = false; }
/// <summary> /// 폰트설치(참조에 Shell32.dll 추가) /// </summary> /// <param name="aFontPath"></param> public static void FontInstall(string aFontPath) { Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder fontFolder = shell.NameSpace(0x14); fontFolder.CopyHere(aFontPath, 16); }
private void button1_Click(object sender, EventArgs e) { if (rememberMeBox.Checked == true) { StreamWriter logininfo = new StreamWriter(@"C:\GMODit\.minecraft\gmoditlastlogin"); logininfo.WriteLine(this.username.Text); string encpass = ""; string temppass = this.password.Text; Random randgen = new Random(234); foreach (char a in temppass.ToString()) { encpass += (char)((int)a + (randgen.Next() % 5)); } logininfo.WriteLine(encpass); logininfo.Close(); } else { StreamWriter logininfo = new StreamWriter(@"C:\GMODit\.minecraft\gmoditlastlogin"); // creates blank file; overwrites old file logininfo.Close(); } bool ismodded = false; bool clientExists = false; string folderlocation = @"C:\GMODIT\.minecraft"; string modlocation = folderlocation + @"\mods"; string coremodlocation = folderlocation + @"\coremods"; string templocation = "c:\\temp\\"; if (Directory.Exists(folderlocation)) { clientExists = true; } if (!Directory.Exists(templocation)) { Directory.CreateDirectory(templocation); } if (File.Exists(folderlocation + "\\version3.modit")) { ismodded = true; } else { //download and extract the three files if (InternetCheck.Checked == true) { WebClient downloader = new WebClient(); label4.Text = "Downloading client"; this.Update(); downloader.DownloadFile("https://site.com/link/to/client.zip", templocation + "client.zip"); label4.Text = "Downloading Mods"; this.Update(); downloader.DownloadFile("https://site.com/link/to/mods.zip", templocation + "mods.zip"); label4.Text = "Downloading Coremods"; this.Update(); downloader.DownloadFile("https://site.com/link/to/coremods.zip", templocation + "coremods.zip"); label4.Text = "Extracting..."; Shell32.Shell sc = new Shell32.Shell(); Directory.CreateDirectory(@"C:\temp\.minecraft"); Shell32.Folder output = sc.NameSpace(@"C:\temp\.minecraft\"); Shell32.Folder input = sc.NameSpace(templocation + "client.zip"); output.CopyHere(input.Items(), 256); Directory.CreateDirectory(@"C:\temp\.minecraft\mods"); output = sc.NameSpace(@"C:\temp\.minecraft\mods"); input = sc.NameSpace(templocation + "mods.zip"); output.CopyHere(input.Items(), 256); Directory.CreateDirectory(@"C:\temp\.minecraft\coremods"); output = sc.NameSpace(@"C:\temp\.minecraft\coremods"); input = sc.NameSpace(templocation + "coremods.zip"); output.CopyHere(input.Items(), 256); label4.Text = "Cleaning up..."; this.Update(); File.Delete(templocation + "client.zip"); File.Delete(templocation + "mods.zip"); File.Delete(templocation + "coremods.zip"); } else { WebClient downloader = new WebClient(); label4.Text = "Downloading full client. May take a while"; this.Update(); downloader.DownloadFile("https://site.com/link/to/client_full.zip", templocation + "client_full.zip"); label4.Text = "Extracting..."; Shell32.Shell sc = new Shell32.Shell(); Directory.CreateDirectory(@"C:\temp\.minecraft"); Shell32.Folder output = sc.NameSpace(@"C:\temp\.minecraft\"); Shell32.Folder input = sc.NameSpace(templocation + "client_full.zip"); output.CopyHere(input.Items(), 256); label4.Text = "Cleaning up..."; File.Delete(templocation + "client_full.zip"); } new Microsoft.VisualBasic.Devices.Computer().FileSystem.CopyDirectory("C:\\temp\\.minecraft", folderlocation, true); Directory.Delete("C:\\temp\\.minecraft", true); clientExists = true; ismodded = true; } if (clientExists && ismodded) { bool authed = false; string user, session = ""; string[] res = verifyUser(username.Text, password.Text, out authed); if (authed) { user = res[2]; session = res[3]; StartMinecraft(user, session); Application.Exit(); } } }
/// <summary> /// Renames Launcher's files and downloads new ones. Unzips them and restarts a Launcher. /// </summary> private void UpdateSelf() { string cwd = Directory.GetCurrentDirectory(); string exeName = cwd + "\\" + AppDomain.CurrentDomain.FriendlyName; MessageBox.Show(c.SubElText("Messages", "OutdatedLauncher")); // Clean up possible mess in the way. if (File.Exists(cwd + "\\OldLauncher.exe")) { File.Delete(cwd + "\\OldLauncher.exe"); } if (File.Exists(cwd + "\\OldLauncherConfig.xml")) { File.Delete(cwd + "\\OldLauncherConfig.xml"); } if (File.Exists(cwd + "\\OldLauncherIcon.ico")) { File.Delete(cwd + "\\OldLauncherIcon.ico"); } // Backup current files. if (File.Exists(exeName)) { File.Move(exeName, cwd + "\\OldLauncher.exe"); } if (File.Exists(cwd + "\\LauncherConfig.xml")) { File.Move(cwd + "\\LauncherConfig.xml", cwd + "\\OldLauncherConfig.xml"); } if (File.Exists(cwd + "\\LauncherIcon.ico")) { File.Move(cwd + "\\LauncherIcon.ico", cwd + "\\OldLauncherIcon.ico"); } try { if (File.Exists(cwd + "\\Launcher.zip")) { File.Delete(cwd + "\\Launcher.zip"); } // Download new Launcher. using (var client = new AmWebClient(3000)) { client.DownloadFile(c.SubElText("Paths", "LauncherPath"), cwd + "\\Launcher.zip"); } // Unzip new Launcher. Shell32.Shell objShell = new Shell32.Shell(); Shell32.Folder destinationFolder = objShell.NameSpace(cwd); Shell32.Folder sourceFile = objShell.NameSpace(cwd + "\\Launcher.zip"); foreach (var zipFile in sourceFile.Items()) { destinationFolder.CopyHere(zipFile, 4 | 16); } // Remove zip. File.Delete(cwd + "\\Launcher.zip"); // Start a new Launcher. Process.Start(exeName); newsPictureBox.CancelAsync(); Close(); } catch (Exception e) { // Return things to previous state. if (File.Exists(cwd + "\\OldLauncher.exe")) { File.Move(cwd + "\\OldLauncher.exe", exeName); } if (File.Exists(cwd + "\\OldLauncherConfig.xml")) { File.Move(cwd + "\\OldLauncherConfig.xml", cwd + "\\LauncherConfig.xml"); } if (File.Exists(cwd + "\\OldLauncherIcon.ico")) { File.Move(cwd + "\\OldLauncherIcon.ico", cwd + "\\LauncherIcon.ico"); } o.Messagebox("CouldNotBeUpdated", e); updateButt.Enabled = false; launchButt.Enabled = false; } }
static void Main(string[] args) { string workingDirectory = Environment.GetEnvironmentVariable("WORKING_DIRECTORY"); string cloudAccount = Environment.GetEnvironmentVariable("CLOUD_ACCOUNT"); string cloudKey = Environment.GetEnvironmentVariable("CLOUD_KEY"); string blobURI = string.Format("https://{0}.blob.core.windows.net", cloudAccount); string workbook = Environment.GetEnvironmentVariable("MICROSOFT.HPC.EXCEL.WORKBOOKPATH"); if (null == workbook || workbook.Equals("")) { return; } string directory = Path.GetDirectoryName(workbook); string lastDirectory = Path.GetFileName(directory); string localDir = Path.Combine(workingDirectory, lastDirectory); if (null == workingDirectory || workingDirectory.Equals("")) { return; } if (null == cloudAccount || cloudAccount.Equals("")) { return; } if (null == cloudKey || cloudKey.Equals("")) { return; } // install: download workbook package, unzip and store if (args[0].ToLower().Equals("install")) { try { Directory.CreateDirectory(localDir); } catch { } string localFile = downloadFile(blobURI, cloudAccount, cloudKey, lastDirectory + ".zip"); // if the file was not found, that's not necessarily an // error; the service might be trying to use a static workbook. // in that case, just exit if (null == localFile || localFile.Equals("")) { Console.WriteLine("Package not found, skipping workbook sync"); return; } // unzip, move. use the shell to unzip Shell32.Folder SrcFlder = GetShell32NameSpace(localFile); Shell32.Folder DestFlder = GetShell32NameSpace(localDir); Shell32.FolderItems items = SrcFlder.Items(); DestFlder.CopyHere(items, 20); // clean up try { File.Delete(localFile); } catch { } } // cleanup: remove the directory else if (args[0].ToLower().Equals("cleanup")) { try { Directory.Delete(localDir, true); } catch { } } }
private static void CopyToFolder(Shell32.Folder srcFolder, Shell32.Folder dstFolder, bool copySubFolders, ref StringCollection resultList) { const string FileTypesNotToCopy = "aspx"; const string FoldersNotToCopy = "forms"; foreach (Shell32.FolderItem item in srcFolder.Items()) { if (item.IsLink) { continue; } if (item.IsFolder && copySubFolders) { Shell32.Folder subFolder = (Shell32.Folder)item.GetFolder; Shell32.FolderItem it = dstFolder.ParseName(subFolder.Title); // Only Copy the folders we want to copy if (FoldersNotToCopy.Contains(subFolder.Title.ToLower())) { continue; //skip folder } // if destination folder doesn't exist create it if (!(it != null && it.Type != null && it.Type != "")) { dstFolder.NewFolder(subFolder.Title, 0x414); } // We can now safely assume we have the folder, so we can copy it it = dstFolder.ParseName(subFolder.Title); CopyToFolder((Shell32.Folder)item.GetFolder, (Shell32.Folder)it.GetFolder, copySubFolders, ref resultList); continue; } string fType = Path.GetExtension(item.Path); fType = fType.TrimStart('.'); // Only Copy the files we want to copy if (FileTypesNotToCopy.Contains(fType.ToLower())) { continue; //skip file } // Add to result set resultList.Add(item.Path); //check if this file already exists locally Shell32.FolderItem si = srcFolder.ParseName(item.Name); Shell32.FolderItem di = dstFolder.ParseName(item.Name); string tmpFile = Path.GetTempPath() + Path.GetFileName(item.Name); // if file already exists - we only copy over when newer if (di != null && di.Type != null && di.Type != "") { // It looks like we first must copy the file over locally into a temp // directory JUST to check the timestamp (modified date) ~very inefficient, but works Shell32.ShellClass shell = new Shell32.ShellClass(); Shell32.Folder tmpFolder = shell.NameSpace(Path.GetTempPath()); if (File.Exists(tmpFile)) // Delete first otherwise Explorer will prompt { File.Delete(tmpFile); } tmpFolder.CopyHere(item, 0x414); Shell32.FolderItem ti = tmpFolder.ParseName(item.Name); // check timestamps of the files if (ti.ModifyDate > di.ModifyDate) { File.Delete(di.Path); // we can delete the old file dstFolder.CopyHere(ti, 0x414); //it appears there is a microsoft bug 0x414 won't do anything } File.Delete(tmpFile); } else // just copy over { dstFolder.CopyHere(item, 0x414); //it appears there is a microsoft bug 0x414 won't do anything } } }
/// <summary> /// ファイル・フォルダ格納 /// </summary> /// <param name="src">コピー元パス</param> public void CopyFrom(string src) { Shell32.FolderItem fi = sh.NameSpace(Path.GetDirectoryName(src)).ParseName(Path.GetFileName(src)); dir.CopyHere(fi, 0); Sync(); }