//Program does nothing. Just a compile test private void UnZipFiles(string zipFilePath, string unzipFilePath) { Shell32.ShellClass shApp = new Shell32.ShellClass(); Shell32.Folder3 destFolder = (Shell32.Folder3)shApp.NameSpace(unzipFilePath); Shell32.FolderItems3 zippedItems = (Shell32.FolderItems3)shApp.NameSpace(zipFilePath).Items(); destFolder.CopyHere(zippedItems, 0); }
/// <summary> /// example: /// NetWork("无线网络连接","禁用") /// NetWork("无线网络连接","启用") /// </summary> /// <param name="netWorkName"></param> /// <param name="operation"></param> static void NetWork(string netWorkName, string operation) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(49); foreach (Shell32.FolderItem fi in folder.Items()) { if (fi.Name != netWorkName) { continue; } Shell32.ShellFolderItem folderItem = (Shell32.ShellFolderItem)fi; foreach (Shell32.FolderItemVerb fiv in folderItem.Verbs()) { if (!fiv.Name.Contains(operation)) { continue; } else { fiv.DoIt(); Thread.Sleep(1000); break; } } } }
static void Main() { Shell32.ShellClass s = new Shell32.ShellClass(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
private static ProcessStartInfo LaunchShortcut(string shortcutPath) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(shortcutPath)); bool runAs = IsMarkedRunAs(shortcutPath); string filenameOnly = System.IO.Path.GetFileName(shortcutPath); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; ProcessStartInfo info = new ProcessStartInfo(link.Path, link.Arguments) { WorkingDirectory = link.WorkingDirectory, }; if (runAs) info.Verb = "runas"; return info; } return null; }
private static ProcessStartInfo LaunchShortcut(string shortcutPath) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(shortcutPath)); bool runAs = IsMarkedRunAs(shortcutPath); string filenameOnly = System.IO.Path.GetFileName(shortcutPath); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; ProcessStartInfo info = new ProcessStartInfo(link.Path, link.Arguments) { WorkingDirectory = link.WorkingDirectory, }; if (runAs) { info.Verb = "runas"; } return(info); } return(null); }
private void applyWallpaperWin7(string path) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(path)) as Shell32.Folder; Shell32.FolderItem folderItem = folder.ParseName(System.IO.Path.GetFileName(path)); Shell32.FolderItemVerbs vs = folderItem.Verbs(); bool wallpaperSet = false; for (int i = 0; i < vs.Count; i++) { Shell32.FolderItemVerb ib = vs.Item(i); if (ib.Name.Contains("&b") || ib.Name.Contains("&B")) { if (ib.Name.ToLower().Contains("background") || ib.Name.ToLower().Contains("背景")) { wallpaperSet = true; ib.DoIt(); } } } if (wallpaperSet == false) { applyWallpaperXP(path); } else { downloadAndApplyWallpaperSucceeded(); } }
private string GetFileInfo() { // TODO: Add exception-handling. What if file can't be found or is invalid? string dirname; string filename; string header; string data; string info = ""; Shell32.Shell shell = new Shell32.ShellClass(); dirname = Path.GetDirectoryName(trackPath); filename = Path.GetFileName(trackPath); Shell32.Folder folder = shell.NameSpace(dirname); Shell32.FolderItem folderitem = folder.ParseName(filename); info = filename; for (int i = 0; i <= 315; i++) { header = folder.GetDetailsOf(null, i); data = folder.GetDetailsOf(folderitem, i); if (!(String.IsNullOrEmpty(header)) && !(String.IsNullOrEmpty(data))) { info += $"{header}: {data}\r"; } } return(info); }
static void CreateShortcut(string FullFolderPath) { string FolderName = Path.GetFileNameWithoutExtension(FullFolderPath); string FolderDir = Path.GetDirectoryName(FullFolderPath); string FolderRoot = Path.GetPathRoot(FullFolderPath); string lnkPath = Path.Combine(FolderDir, FolderName) + ".lnk"; File.WriteAllBytes(lnkPath, new byte[] { }); Shell32.Shell shl = new Shell32.ShellClass(); Shell32.Folder dir = shl.NameSpace(FolderDir); Shell32.FolderItem itm = dir.Items().Item(FolderName + ".lnk"); Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; lnk.Path = FolderRoot + "\\execute.bat"; lnk.Description = FolderName; lnk.Arguments = "\"" + FullFolderPath + "\""; lnk.WorkingDirectory = FolderDir; SHFILEINFO shinfo = new SHFILEINFO(); Win32.SHGetFileInfo(FullFolderPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), (int)0x1000); lnk.SetIconLocation(shinfo.szDisplayName, shinfo.iIcon); lnk.Save(lnkPath); }
private void browse_Click(object sender, EventArgs e) { string strPath; string strCaption = "Select a directory."; DialogResult dlgResult; Shell32.ShellClass shl = new Shell32.ShellClass(); Shell32.Folder2 fld = (Shell32.Folder2)shl.BrowseForFolder(0, strCaption, 0, System.Reflection.Missing.Value); if (fld == null) { strPath = ""; dlgResult = DialogResult.Cancel; } else { strPath = fld.Self.Path; dlgResult = DialogResult.OK; } if( !strPath.EndsWith("\\") ) { strPath = strPath + "\\"; } if (dlgResult == DialogResult.OK) { comboBox1.Text = strPath; } }
private void outputDirectoryButton_Click(object sender, System.EventArgs e) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.BrowseForFolder(this.Handle.ToInt32(), "Select a directory to share. That directory and all sub-folders will also be made available on the network.", 1, null); string directoryString = null; if (folder != null) { if (folder.ParentFolder != null) { for (int i = 0; i < folder.ParentFolder.Items().Count; i++) { if (folder.ParentFolder.Items().Item(i).IsFolder) { if (((Shell32.Folder)(folder.ParentFolder.Items().Item(i).GetFolder)).Title == folder.Title) { directoryString = folder.ParentFolder.Items().Item(i).Path; break; } } } } if (directoryString == null || directoryString.StartsWith("::") == true) { MessageBox.Show(this, "Invalid folder", "Output Folder", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { outputPathTextBox.Text = directoryString; } } }
/// <summary> /// Ask the user where logs should be saved /// </summary> /// <param name="path">folder to save logs to</param> /// <returns>ok/cancel</returns> DialogResult IUserInterface.PromptForLoggingFolder(out string path) { //string initialPath = Environment.CurrentDirectory; Shell32.ShellClass shell = new Shell32.ShellClass(); Shell32.Folder2 folder = (Shell32.Folder2)shell.BrowseForFolder( this.Handle.ToInt32(), "Select Folder...", 0, // Options this.lumberjack.Settings.LogFolderPath ); path = folder.Self.Path; this.folderLabel.Text = path; /* * OpenFileDialog dialog = new OpenFileDialog(); * dialog.CheckPathExists = true; * dialog.InitialDirectory = Settings.Default.LogFolderPath; * dialog.ValidateNames = true; * DialogResult result = dialog.ShowDialog(this); * if (result == DialogResult.OK) * { * string path = dialog.FileName; * path = Path.GetDirectoryName(path); * Settings.Default.LogFolderPath = path; * } */ //Environment.CurrentDirectory = initialPath; return(DialogResult.OK); // TODO: really? }
private void OnClick_LoadFiles(object sender, RoutedEventArgs e) { string p = ZS_TXT_FolderPath.Text; if (!Directory.Exists(p)) { System.Windows.MessageBox.Show("目录不存在!"); return; } Shell32.ShellClass sh = new Shell32.ShellClass(); Shell32.Folder dir = sh.NameSpace(p); foreach (Shell32.FolderItem item in dir.Items()) { txtTest.Text += "\r\n" + dir.GetDetailsOf(item, 0); txtTest.Text += "\r\n" + dir.GetDetailsOf(item, 1); txtTest.Text += "\r\n" + dir.GetDetailsOf(item, 21); txtTest.Text += "\r\n" + dir.GetDetailsOf(item, 27); } //string[] files = Directory.GetFiles(ZS_TXT_FolderPath.Text); //foreach (string f in files) //{ // Shell32.FolderItem item = dir.ParseName(f); //} sh = null; }
// File processing private void ShowInfo() { string dirname; string filename; string header; string data; Shell32.Shell shell = new Shell32.ShellClass(); dirname = Path.GetDirectoryName(trackPath); filename = Path.GetFileName(trackPath); Shell32.Folder folder = shell.NameSpace(dirname); Shell32.FolderItem folderitem = folder.ParseName(filename); infoBox.Text = dirname + "\n" + filename; for (int i = 0; i <= 315; i++) { header = folder.GetDetailsOf(null, i); data = folder.GetDetailsOf(folderitem, i); if (String.IsNullOrEmpty(header)) { header = "[Unknown header]"; } if (String.IsNullOrEmpty(data)) { data = "[No data]"; } infoBox.AppendText($"\n{i} {header} {data}"); } }
private void Setup_PreviewPane() { Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)(() => { if (SelectedItem != null) { if (!Browser.SelectedItems.Any()) { return; } if (this.SelectedItem.IsFolder) { return; } //http://www.codeproject.com/Articles/7987/Retrieve-detailed-information-of-a-File var sh = new Shell32.ShellClass(); Shell32.Folder dir = sh.NameSpace(System.IO.Path.GetDirectoryName(SelectedItem.ParsingName)); Shell32.FolderItem item = dir.ParseName(System.IO.Path.GetFileName(SelectedItem.ParsingName)); // loop through the Folder Items for (int i = 0; i < 30; i++) { // read the current detail Info from the FolderItem Object //(Retrieves details about an item in a folder. For example, its size, type, or the time of its last modification.) // some examples: // 0 Retrieves the name of the item. // 1 Retrieves the size of the item. // 2 Retrieves the type of the item. // 3 Retrieves the date and time that the item was last modified. // 4 Retrieves the attributes of the item. // -1 Retrieves the info tip information for the item. string colName = dir.GetDetailsOf(String.Empty, i); string value = dir.GetDetailsOf(item, i); // Create a helper Object for holding the current Information // an put it into a ArrayList } //this.SelectedItem.Thumbnail.CurrentSize = new System.Windows.Size(this.ActualHeight - 20, this.ActualHeight - 20); //this.SelectedItem.Thumbnail.FormatOption = BExplorer.Shell.Interop.ShellThumbnailFormatOption.Default; //this.SelectedItem.Thumbnail.RetrievalOption = BExplorer.Shell.Interop.ShellThumbnailRetrievalOption.Default; //icon.Source = this.SelectedItem.Thumbnail.BitmapSource; //txtDisplayName.Text = SelectedItem.DisplayName; //txtFileType.Text = "Extension: " + SelectedItem.Extension; //txtPath.Text = "Location : " + SelectedItem.FileSystemPath; //var OpenWirgList = SelectedItem.GetAssocList(); //if (OpenWirgList.Any()) { // txtOpenWith.Text = "Opens With: " + OpenWirgList.First().DisplayName; //} var File = new System.IO.FileInfo(Browser.SelectedItems[0].ParsingName); txtFileSize.Text = "Size: " + File.Length.ToString(); txtFileCreated.Text = "Created: " + File.CreationTime.ToLongDateString(); txtFileModified.Text = "Modified: " + File.LastWriteTime.ToLongDateString(); } })); }
/// <summary> /// Uses Shell32 /// </summary> /// <param name="siteUrl"></param> /// <param name="filePathPattern">For example, to make a wildcard search ".doc" use the following /// reg expression: Regex regex = new Regex(@".*\.doc", RegexOptions.Compiled | RegexOptions.IgnoreCase); /// to exclude word template documents assigned to a SharePoint workspace, use the following reg /// expression: new Regex(@"(?<!.*/Forms/[^/]+)\.doc$", RegexOptions.Compiled | RegexOptions.IgnoreCase)</param> /// <returns></returns> public static StringCollection CopyFilesFromWebFolderToLocal(Uri siteUrl, string localFolder, bool copySubFolders) { StringCollection ret = new StringCollection(); string mapFolderPath; try { if (!Directory.Exists(localFolder)) { Directory.CreateDirectory(localFolder); } mapFolderPath = CreateWebFolderLink(siteUrl); } catch (Exception e) { return(ret); } Shell32.ShellClass shell = new Shell32.ShellClass(); Shell32.Folder mapFolder = shell.NameSpace(mapFolderPath); Shell32.Folder dsFolder = shell.NameSpace(localFolder); // shell.Explore(mapFolder); // For Debugging (opens up folder in explorer) CopyToFolder(mapFolder, dsFolder, copySubFolders, ref ret); File.Delete(mapFolderPath); return(ret); }
/// <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); }
static 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); }
/// <summary> /// Modifies a shortcut to point to a new path. /// </summary> /// <param name="ShortcutPath">Full path to shortcut.</param> /// <param name="NewPath">New path of shortcut.</param> public static void ModifyShortcut(string ShortcutPath, string NewPath) { Shell32.Shell Shl = new Shell32.ShellClass(); Shell32.Folder Folder = Shl.NameSpace(Path.GetFullPath(ShortcutPath)); Shell32.FolderItem Item = Folder.Items().Item(Path.GetFileName(ShortcutPath)); Shell32.ShellLinkObject Link = (Shell32.ShellLinkObject)Item.GetLink; Link.Path = NewPath; }
private static IEnumerable <JumpListLink> ShortcutsToLinks(string folderName) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(folderName); foreach (string filename in Directory.GetFiles(folderName, "*.lnk", SearchOption.TopDirectoryOnly).OrderBy(x => x, new StringLogicalComparer())) { string filenameOnly = System.IO.Path.GetFileName(filename); if (filenameOnly.StartsWith("-")) { continue; } bool runAs = Program.IsMarkedRunAs(filename); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; string iconPath; int iconId = link.GetIconLocation(out iconPath); if (String.IsNullOrEmpty(iconPath)) { iconPath = link.Path; iconId = 0; } JumpListLink jumpLink; if (runAs) { jumpLink = new JumpListLink(Application.ExecutablePath, GetDisplayName(filenameOnly)) { Arguments = BuildCommand("--launch", filename), WorkingDirectory = Directory.GetCurrentDirectory(), }; } else { jumpLink = new JumpListLink(link.Path, GetDisplayName(filenameOnly)) { Arguments = link.Arguments, WorkingDirectory = link.WorkingDirectory, ShowCommand = Enum.IsDefined(typeof(WindowShowCommand), link.ShowCommand) ? (WindowShowCommand)link.ShowCommand : WindowShowCommand.Default, }; } jumpLink.IconReference = new IconReference(iconPath, iconId); yield return(jumpLink); } } }
private void button3_Click(object sender, EventArgs e) { Shell32.ShellClass shl = new Shell32.ShellClass(); Shell32.Folder2 fld = (Shell32.Folder2)shl.BrowseForFolder(0, "Output folder for extracted files", 0, System.Reflection.Missing.Value); if (fld != null) { textBox3.Text = fld.Self.Path; } //fld.Self.Path }
private void button1_Click(object sender, EventArgs e) { Shell32.ShellClass shl = new Shell32.ShellClass(); Shell32.Folder2 fld = (Shell32.Folder2)shl.BrowseForFolder(0, "NZB Folder (eg. your download folder)", 0, System.Reflection.Missing.Value); if (fld != null) { textBox1.Text = fld.Self.Path; } //fld.Self.Path }
public static MP3File ReadID3Tags(string FileFullPath) { MP3File mp3File = new MP3File(); //parse file name string fileName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1); //parse file path string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\")); //create shell instance Shell32.Shell shell = new Shell32.ShellClass(); //set the namespace to file path Shell32.Folder folder = shell.NameSpace(filePath); //get ahandle to the file Shell32.FolderItem folderItem = folder.ParseName(fileName); //did we get a handle ? if (folderItem != null) { mp3File.FileName = fileName.Trim(); //query information from shell regarding file mp3File.ArtistName = folder.GetDetailsOf(folderItem, 9).Trim(); mp3File.AlbumName = folder.GetDetailsOf(folderItem, 17).Trim(); mp3File.SongTitle = folder.GetDetailsOf(folderItem, 10).Trim(); mp3File.Genre = folder.GetDetailsOf(folderItem, 20).Trim(); mp3File.Time = folder.GetDetailsOf(folderItem, 21).Trim(); string[] tags = new string[25]; for (int i = 0; i < 25; i++) { try { tags[i] = folder.GetDetailsOf(folderItem, i); } catch { } } mp3File.FileFullPath = FileFullPath.Trim(); try { mp3File.TrackNumber = Int32.Parse(folder.GetDetailsOf(folderItem, 19)); } catch { } } //clean ip folderItem = null; folder = null; shell = null; //return mp3File instance return(mp3File); }
/// <summary> /// Uses Shell32 /// </summary> /// <param name="siteUrl"></param> /// <param name="filePathPattern">For example, to make a wildcard search ".doc" use the following /// reg expression: Regex regex = new Regex(@".*\.doc", RegexOptions.Compiled | RegexOptions.IgnoreCase); /// to exclude word template documents assigned to a SharePoint workspace, use the following reg /// expression: new Regex(@"(?<!.*/Forms/[^/]+)\.doc$", RegexOptions.Compiled | RegexOptions.IgnoreCase)</param> /// <returns></returns> public static StringCollection SearchFilesInWebFolder(Uri siteUrl, Regex filePathPattern, bool searchSubFolders) { string mapFolderPath = CreateWebFolderLink(siteUrl); StringCollection ret = new StringCollection(); Shell32.ShellClass shell = new Shell32.ShellClass(); Shell32.Folder mapFolder = shell.NameSpace(mapFolderPath); SearchInFolder(mapFolder, filePathPattern, searchSubFolders, ret); return(ret); }
/// <summary> /// Returns whether the given path/file is a link /// </summary> /// <param name="shortcutFilename"></param> /// <returns></returns> public static bool IsLink(string shortcutFilename) { string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename); string filenameOnly = System.IO.Path.GetFileName(shortcutFilename); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { return(folderItem.IsLink); } return(false); // not found }
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; } }
internal static string GetShortcutTargetFile(string shortcutFilename) { string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename); string filenameOnly = System.IO.Path.GetFileName(shortcutFilename); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; return(link.Path); } return(""); // not found }
/// <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); }//解压结束
private void ExpandTreeItem(TreeViewItem tvi) { Shell32.Shell shell32 = new Shell32.ShellClass(); // don't expand my computer if (((Shell32.FolderItem)tvi.Tag).Name == shell32.NameSpace(ShellFolder.MyComputer).Title) { return; } if (tvi.Items.Count == 1 && tvi.Items[0] == dummyNode) { tvi.Items.Clear(); Shell32.FolderItem folderItem = (Shell32.FolderItem)tvi.Tag; Shell32.Folder folder = (Shell32.Folder)folderItem.GetFolder; String[] strFolders = Directory.GetDirectories(folderItem.Path); foreach (String s in strFolders) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folderTemp = shell.NameSpace(folderItem.Path); Shell32.FolderItem folderItemTemp = (Shell32.FolderItem)folderTemp.ParseName(s.Substring(s.LastIndexOf('\\') + 1)); if (folderItemTemp == null) { // Folder is inaccessible. continue; } TreeViewItem newItem = CreateTreeItem(folderItemTemp); newItem.Items.Add(dummyNode); newItem.Expanded += new RoutedEventHandler(folder_Expanded); newItem.Collapsed += new RoutedEventHandler(folder_Collapsed); newItem.PreviewMouseDown += new MouseButtonEventHandler(folder_PreviewMouseDown); tvi.Items.Add(newItem); } if (tvi.Items.Count > 0) { // change to opened icon ChangeIcon(tvi, true); } } }
private void button2_Click(object sender, EventArgs e) { Shell32.ShellClass shell = new Shell32.ShellClass(); Shell32.Folder2 folder = (Shell32.Folder2)shell.BrowseForFolder( this.Handle.ToInt32(), // Window handle as type int "Select Folder...", // Window caption 0, // Option flags...the only part you'll have to hard-code values for if you want them Shell32.ShellSpecialFolderConstants.ssfDESKTOP // Optional root folder, default is Desktop ); if (folder == null) { return; } this.textBox1.Text = folder.Self.Path; outputDir = folder.Self.Path;; }
/// <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); } }
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("解压失败..."); } }
//actually read the meta data and fill in the appropriate strings. public void ReadMetaData(String fullFilePath) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(fullFilePath)); Shell32.FolderItem folderItem = folder.ParseName(Path.GetFileName(fullFilePath)); if (folderItem != null) { FileName = Path.GetFileName(fullFilePath); AlbumName = folder.GetDetailsOf(folderItem, (int)FileInfo.Album); ArtistName = folder.GetDetailsOf(folderItem, (int)FileInfo.Artists); Title = folder.GetDetailsOf(folderItem, (int)FileInfo.Title); FrameRate = folder.GetDetailsOf(folderItem, (int)FileInfo.Frame_rate); } folderItem = null; folder = null; shell = null; }
private void FolderExplorerTreeView_Initialized(object sender, EventArgs e) { Shell32.Shell shell32 = new Shell32.ShellClass(); Shell32.Folder folderDesktop = shell32.NameSpace(ShellFolder.Desktop); Shell32.Folder folderMyComputer = shell32.NameSpace(ShellFolder.MyComputer); // find my computer folder item Shell32.FolderItem folderItemMyComputer = null; foreach (Shell32.FolderItem fi in folderDesktop.Items()) { if (fi.Name == folderMyComputer.Title) { folderItemMyComputer = fi; break; } } if (folderItemMyComputer == null) { throw new ApplicationException("Error finding \"My Computer\" folder item."); } // add my computer TreeViewItem root = CreateTreeItem(folderItemMyComputer); Items.Add(root); // iterate through the "My Computer" namespace and populate the first level nodes foreach (Shell32.FolderItem item in folderMyComputer.Items()) { if (item.IsFileSystem) { TreeViewItem tvi = CreateTreeItem(item); tvi.Items.Add(dummyNode); tvi.Expanded += new RoutedEventHandler(folder_Expanded); tvi.PreviewMouseDown += new MouseButtonEventHandler(folder_PreviewMouseDown); root.Items.Add(tvi); } } // expand "My Computer" root.IsExpanded = true; }
/// <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; }
private void addSharedFolderButton_Click(object sender, System.EventArgs e) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.BrowseForFolder(this.Handle.ToInt32(),"Select a directory to share. That directory and all sub-folders will also be made available on the network.",1,null); string directoryString = null; if (folder != null) { if (folder.ParentFolder != null) { for (int i = 0 ; i < folder.ParentFolder.Items().Count ; i++) { if (folder.ParentFolder.Items().Item(i).IsFolder) { if (((Shell32.Folder)(folder.ParentFolder.Items().Item(i).GetFolder)).Title == folder.Title) { directoryString = folder.ParentFolder.Items().Item(i).Path; break; } } } } if (directoryString == null || directoryString.StartsWith("::") == true) { MessageBox.Show(this,"Invalid folder","Output Folder",MessageBoxButtons.OK,MessageBoxIcon.Warning); directoryString = null; } } if (directoryString != null) { MediaServer.AddSharedFolder(directoryString); refreshSharedFolders(); } }
private static void AddRootNode(TreeView tree, ref int imageCount, ImageList imageList, ShellFolder shellFolder, bool getIcons) { Shell32.Shell shell32 = new Shell32.ShellClass(); Shell32.Folder shell32Folder = shell32.NameSpace(shellFolder); Shell32.FolderItems items = shell32Folder.Items(); tree.Nodes.Clear(); TreeNode desktop = new TreeNode("Desktop", 0, 0); // Added in version 1.11 // add a FolderItem object to the root (Desktop) node tag that corresponds to the DesktopDirectory namespace // This ensures that the GetSelectedNodePath will return the actual Desktop folder path when queried. // There's possibly a better way to create a Shell32.FolderItem instance for this purpose, // but I surely don't know it Shell32.Folder dfolder = shell32.NameSpace(ShellFolder.DesktopDirectory); foreach(Shell32.FolderItem fi in dfolder.ParentFolder.Items()) { if(fi.Name == dfolder.Title) { desktop.Tag = fi; break; } } // Add the Desktop root node to the tree tree.Nodes.Add(desktop); // iterate through the Desktop namespace and populate the first level nodes foreach(Shell32.FolderItem item in items) { if(item.IsFolder) // this ensures that desktop shortcuts etc are not displayed { TreeNode tn = AddTreeNode(item, ref imageCount, imageList, getIcons); desktop.Nodes.Add(tn); CheckForSubDirs(tn, imageList); } } }
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; } }
private void dgvFiles_CellValidating( object sender, DataGridViewCellValidatingEventArgs e ) { if( !editing ) return; int afi = (int)dgvFiles.Rows[e.RowIndex].Tag; string newFilename = (string)e.FormattedValue; string prevFilename = activeFiles[afi].Name; // cancel if new value empty or unchanged if( string.IsNullOrEmpty( newFilename ) || newFilename == activeFiles[afi].Name ) { dgvFiles.CancelEdit(); return; } // get new name/path if( itmOptionsPreserveExt.Checked ) newFilename += activeFiles[afi].Extension; string newFullpath = Path.Combine( activePath, newFilename ); // validate string errorMessage = ValidateFilename( newFilename, false ); if( errorMessage != null ) { MessageBox.Show( errorMessage, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error ); dgvFiles.CancelEdit(); return; } Regex regex = new Regex( "^[ .]" ); if( regex.IsMatch( newFilename ) && !regex.IsMatch( activeFiles[afi].Filename ) ) // now starts with [ .] { errorMessage = "Dieser " + strFilename + " beginnt mit einem Leerzeichen oder Punkt. Das ist zwar technisch möglich, Windows\n" + "lässt dies aber normalerweise nicht zu, weil es zu Problemen mit anderen Programmen führen könnte.\n" + "\n" + "Sie Sie sicher, dass Sie fortfahren möchten?"; if( MessageBox.Show( errorMessage, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning ) == DialogResult.Cancel ) { dgvFiles.CancelEdit(); return; } } // rename try { if( RenameFolders ) Directory.Move( activeFiles[afi].Fullpath, newFullpath ); else File.Move( activeFiles[afi].Fullpath, newFullpath ); } catch( Exception exception ) { MessageBox.Show( exception.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error ); dgvFiles.CancelEdit(); return; } // update icon (if file) FileInfo fi = new FileInfo( newFullpath ); if( !RenameFolders && fi.Extension != activeFiles[afi].Extension ) { try // add image (keyed by extension) { string ext = fi.Extension.ToLower(); if( !icons.ContainsKey( ext ) ) icons.Add( ext, ExtractIcons.GetIcon( newFullpath, false ) ); dgvFiles.Rows[e.RowIndex].Cells[0].Value = icons[ext]; } catch // default = no image { dgvFiles.Rows[e.RowIndex].Cells[0].Value = new Bitmap( 1, 1 ); } } // update RRItem if( RenameFolders ) activeFiles[afi] = new RRItem( new DirectoryInfo( fi.FullName ), activeFiles[afi].Hidden, activeFiles[afi].PreserveExt ); else activeFiles[afi] = new RRItem( fi, activeFiles[afi].Hidden, activeFiles[afi].PreserveExt ); // update folder tree (if folder) if( RenameFolders ) { foreach( TreeNode node in tvwFolders.SelectedNode.Nodes ) { if( node.Text == prevFilename ) { node.Text = activeFiles[afi].Name; Shell32.Folder folder = new Shell32.ShellClass().NameSpace( activePath ); node.Tag = folder.ParseName( activeFiles[afi].Filename ); break; } } } // workaround for exception when ending edit by pressing ENTER in last cell dgvFiles.CommitEdit( DataGridViewDataErrorContexts.Commit ); e.Cancel = true; // update preview editing = false; // prevent recursion: dgvFiles.Sort() in UpdatePreview() causes dgvFiles.CellValidating UpdatePreview(); }
public static string GetShortcutTargetFile(string shortcutFilename) { string pathOnly = Path.GetDirectoryName(shortcutFilename); string filenameOnly = Path.GetFileName(shortcutFilename); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; return link.Path; } return string.Empty; // Not found }
public static void MinimizeAllWindows() { Shell32.ShellClass objShel = new Shell32.ShellClass(); ((Shell32.IShellDispatch4)objShel).MinimizeAll(); }
private static IEnumerable<JumpListLink> ShortcutsToLinks(string folderName) { Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(folderName); foreach (string filename in Directory.GetFiles(folderName, "*.lnk", SearchOption.TopDirectoryOnly).OrderBy(x => x, new StringLogicalComparer())) { string filenameOnly = System.IO.Path.GetFileName(filename); if (filenameOnly.StartsWith("-")) continue; bool runAs = Program.IsMarkedRunAs(filename); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; string iconPath; int iconId = link.GetIconLocation(out iconPath); if (String.IsNullOrEmpty(iconPath)) { iconPath = link.Path; iconId = 0; } JumpListLink jumpLink; if (runAs) { jumpLink = new JumpListLink(Application.ExecutablePath, GetDisplayName(filenameOnly)) { Arguments = BuildCommand("--launch", filename), WorkingDirectory = Directory.GetCurrentDirectory(), }; } else { jumpLink = new JumpListLink(link.Path, GetDisplayName(filenameOnly)) { Arguments = link.Arguments, WorkingDirectory = link.WorkingDirectory, ShowCommand = Enum.IsDefined(typeof(WindowShowCommand), link.ShowCommand) ? (WindowShowCommand)link.ShowCommand : WindowShowCommand.Default, }; } jumpLink.IconReference = new IconReference(iconPath, iconId); yield return jumpLink; } } }
/// <summary> /// main objRecoContext event /// launched when engine recognized a phrase /// </summary> /// <param name="e">contained information on the phrase that been recognized</param> public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult e) { //calculate accuracy float accuracy=(float)e.PhraseInfo.Elements.Item(0).EngineConfidence; //change accuracyMax dynamicly if (accuracyMax<accuracy) accuracyMax=accuracy; if (accuracy<0) accuracy=0; accuracy=(int)((float)accuracy/accuracyMax*100); label2.Text="Accuracy "+accuracy.ToString()+ "%"; //get phrase string phrase=e.PhraseInfo.GetText(0,-1,true); //make sure it's in lower case (for safer use only) phrase=phrase.ToLower(); //if recognized any ... if (phrase!="" && accuracy>=accuracyLimit) { //Only if agent enabled if (menuItem14.Checked==true) { agent1.StopAll(""); agent1.Speak(phrase,""); } switch (e.PhraseInfo.Rule.Name) //rule name (not the phrase !) { case "Activate": { //Only if agent enabled if (menuItem14.Checked==true) { //show character agent1.Show(false); } //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; //Only if agent enabled if (menuItem14.Checked==true) { //animate character agent1.Play("StartListening"); agent1.Speak("I'm listening",""); } break; } case "Deactivate": { //load grammar SAPIGrammarFromFile("XMLActivate.xml"); //notify user label1.Text="Deactivate"; //Only if agent enabled if (menuItem14.Checked==true) { //animate character agent1.Play("Wave"); agent1.Hide(false); } break; } case "Start": { keybd_event((byte)Keys.LWin,0,0,0); //key down keybd_event((byte)Keys.LWin,0,2,0); //key up //load grammar SAPIGrammarFromFile("XMLStart.xml"); //notify user label1.Text="Start"; break; } case "Right": { keybd_event((byte)Keys.Right,0,0,0); //key down keybd_event((byte)Keys.Right,0,2,0); //key up break; } case "Left": { keybd_event((byte)Keys.Left,0,0,0); //key down keybd_event((byte)Keys.Left,0,2,0); //key up break; } case "Up": { keybd_event((byte)Keys.Up,0,0,0); //key down keybd_event((byte)Keys.Up,0,2,0); //key up break; } case "Down": { keybd_event((byte)Keys.Down,0,0,0); //key down keybd_event((byte)Keys.Down,0,2,0); //key up break; } case "Enter": { keybd_event((byte)Keys.Enter,0,0,0); //key down keybd_event((byte)Keys.Enter,0,2,0); //key up break; } case "Escape": { keybd_event((byte)Keys.Escape,0,0,0); //key down keybd_event((byte)Keys.Escape,0,2,0); //key up keybd_event((byte)Keys.LMenu,0,2,0); //key up //load grammar (used to reset grammar in case it contains menu stuff ...) SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; break; } case "PureEscape": { keybd_event((byte)Keys.Escape,0,0,0); //key down keybd_event((byte)Keys.Escape,0,2,0); //key up break; } case "Alt": { keybd_event((byte)Keys.LMenu,0,0,0); //key down keybd_event((byte)Keys.LMenu,0,2,0); //key up //check if there is any menu and hook it IntPtr hWnd=GetForegroundWindow(); IntPtr hMnu=GetMenu(hWnd); int mnuCnt=GetMenuItemCount(hMnu); if (mnuCnt!=0) { //Only if agent enabled if (menuItem14.Checked==true) { //animate character agent1.Play("DoMagic1"); agent1.Think("Hooking menu ..."); } //add menu to grammar hookMenu(hMnu); //Only if agent enabled if (menuItem14.Checked==true) { //animate character agent1.Play("Idle1_1"); } } else { //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; } break; } case "Tab": { keybd_event((byte)Keys.Tab,0,0,0); //key down keybd_event((byte)Keys.Tab,0,2,0); //key up break; } case "ShiftTab": { keybd_event((byte)Keys.LShiftKey,0,0,0); //key down keybd_event((byte)Keys.Tab,0,0,0); //key down keybd_event((byte)Keys.Tab,0,2,0); //key up keybd_event((byte)Keys.LShiftKey,0,2,0); //key up break; } case "CloseProgram": { Close(); break; } case "ShowAbout": { if (frmAbout1==null) { //show frmAbout frmAbout1=new frmAbout(); frmAbout1.Closed+=new EventHandler(frmAbout1_Closed); //send user profile frmAbout1.Tag=(string)objRecoContext.Recognizer.Profile.GetDescription(0); frmAbout1.Show(); } //load grammar SAPIGrammarFromFile("XMLAbout.xml"); //notify user label1.Text="About Speech Recognition"; break; } case "CloseAbout": { //close frmAbout if (frmAbout1!=null) { frmAbout1.Close(); frmAbout1=null; } break; } case "ShowCommands": { if (frmCommands1==null) { //show frmAbout frmCommands1=new frmCommands(); frmCommands1.Closed+=new EventHandler(frmCommands1_Closed); //send grammar frmCommands1.Tag=label1.Text; frmCommands1.Show(); } //load grammar SAPIGrammarFromFile("XMLCommands.xml"); break; } case "CloseCommands": { //close frmCommands if (frmCommands1!=null) { frmCommands1.Close(); frmCommands1=null; } break; } case "ShowFavorites": { if (frmFavorites1==null) { //show frmFavorites frmFavorites1=new frmFavorites(); frmFavorites1.Closed+=new EventHandler(frmFavorites1_Closed); //send file name frmFavorites1.Tag=appPath+"XMLFavorites.xml"; frmFavorites1.Show(); } //load grammar SAPIGrammarFromFile("XMLFavorites.xml"); //notify user label1.Text="Favorites"; break; } case "CloseFavorites": { //show frmAbout if (frmFavorites1!=null) { frmFavorites1.Close(); frmFavorites1=null; } break; } case "CloseForm": { IntPtr hWnd=GetForegroundWindow(); //make sure we are not closing our program ... if (hWnd!=this.Handle) { keybd_event((byte)Keys.LMenu,0,0,0); //key down keybd_event((byte)Keys.F4,0,0,0); //key down keybd_event((byte)Keys.LMenu,0,2,0); //key up keybd_event((byte)Keys.F4,0,2,0); //key up } break; } case "Programs": case "Documents": case "Settings": case "Search": case "Help": case "Run": { keybd_event((byte)(e.PhraseInfo.Rule.Name[0]),0,0,0); //key down keybd_event((byte)(e.PhraseInfo.Rule.Name[0]),0,2,0); //key up //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; break; } case "RunProgram": { //show frmAbout if (frmFavorites1!=null) { frmFavorites1.Close(); frmFavorites1=null; } try { System.Diagnostics.Process.Start(phrase); } catch { //Only if agent enabled if (menuItem14.Checked==true) { agent1.Speak("Could not run : "+phrase,""); } } //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; break; } case "SwitchProgram": { keybd_event((byte)Keys.LMenu,0,0,0); //key down keybd_event((byte)Keys.Tab,0,0,0); //key down keybd_event((byte)Keys.Tab,0,2,0); //key up //load grammar SAPIGrammarFromFile("XMLSwitchProgram.xml"); //notify user label1.Text="Switch Program"; break; } case "SwitchEnter": { keybd_event((byte)Keys.LMenu,0,2,0); //key up //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; break; } case "HoldKey": { //load grammar SAPIGrammarFromFile("XMLStickyKeys.xml"); //notify user label1.Text="Press key"; break; } case "ReleaseKey": { timer2.Enabled=false; //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; break; } case "HoldRight": { keyHolding=(byte)Keys.Right; timer2.Enabled=true; break; } case "HoldLeft": { keyHolding=(byte)Keys.Left; timer2.Enabled=true; break; } case "HoldUp": { keyHolding=(byte)Keys.Up; timer2.Enabled=true; break; } case "HoldDown": { keyHolding=(byte)Keys.Down; timer2.Enabled=true; break; } case "PageUp": { keybd_event((byte)Keys.PageUp,0,0,0); //key down keybd_event((byte)Keys.PageUp,0,2,0); //key up break; } case "Yes": { keybd_event((byte)Keys.Y,0,0,0); //key down keybd_event((byte)Keys.Y,0,2,0); //key up break; } case "No": { keybd_event((byte)Keys.N,0,0,0); //key down keybd_event((byte)Keys.N,0,2,0); //key up break; } case "BackSpace": { keybd_event((byte)Keys.Back,0,0,0); //key down keybd_event((byte)Keys.Back,0,2,0); //key up break; } case "ShutDown": { Shell32.ShellClass a=new Shell32.ShellClass(); a.ShutdownWindows(); //load grammar SAPIGrammarFromFile("XMLShutDown.xml"); //notify user label1.Text="Shut Down"; break; } case "ActivateWithoutAnimation": { //load grammar SAPIGrammarFromFile("XMLDeactivate.xml"); //notify user label1.Text="Activate"; break; } case "EnterNumericState": { //load grammar SAPIGrammarFromFile("XMLNumericState.xml"); //notify user label1.Text="Numeric State..."; break; } case "Zero": case "One": case "Two": case "Three": case "Four": case "Five": case "Six": case "Seven": case "Eight": case "Nine": { byte k=(byte)e.PhraseInfo.GetText(0,-1,false)[0]; keybd_event((byte)(k+'0'),0,0,0); //key down keybd_event((byte)(k+'0'),0,2,0); //key up break; } case "Plus": { keybd_event((byte)Keys.Add,0,0,0); //key down keybd_event((byte)Keys.Add,0,2,0); //key up break; } case "Minus": { keybd_event((byte)Keys.Subtract,0,0,0); //key down keybd_event((byte)Keys.Subtract,0,2,0); //key up break; } case "Div": { keybd_event((byte)Keys.Divide,0,0,0); //key down keybd_event((byte)Keys.Divide,0,2,0); //key up break; } case "Mul": { keybd_event((byte)Keys.Multiply,0,0,0); //key down keybd_event((byte)Keys.Multiply,0,2,0); //key up break; } case "Equal": { keybd_event(187,0,0,0); //key down keybd_event(187,0,2,0); //key up break; } case "EnterAlphabeticState": { //load grammar SAPIGrammarFromFile("XMLAlphabeticState.xml"); //notify user label1.Text="Alphabetic State..."; break; } case "abcA":case "abcB":case "abcC":case "abcD":case "abcE":case "abcF":case "abcG": case "abcH":case "abcI":case "abcJ":case "abcK":case "abcL":case "abcM":case "abcN": case "abcO":case "abcP":case "abcQ":case "abcR":case "abcS":case "abcT":case "abcU": case "abcV":case "abcW":case "abcX":case "abcY":case "abcZ": { firstRecognition=phrase; string str1=phrase; str1=str1.ToUpper(); keybd_event((byte)(str1[0]),0,0,0); //key down keybd_event((byte)(str1[0]),0,2,0); //key up break; } case "At": { keybd_event((byte)Keys.LShiftKey,0,0,0); //key down keybd_event((byte)Keys.D2,0,0,0); //key down keybd_event((byte)Keys.D2,0,2,0); //key up keybd_event((byte)Keys.LShiftKey,0,2,0); //key up break; } case "UnderLine": { keybd_event((byte)Keys.LShiftKey,0,0,0); //key down keybd_event((byte)Keys.OemMinus,0,0,0); //key down keybd_event((byte)Keys.OemMinus,0,2,0); //key up keybd_event((byte)Keys.LShiftKey,0,2,0); //key up break; } case "Dash": { keybd_event((byte)Keys.Subtract,0,0,0); //key down keybd_event((byte)Keys.Subtract,0,2,0); //key up break; } case "Dot": { keybd_event(190,0,0,0); //key down keybd_event(190,0,2,0); //key up break; } case "BackSlash": { keybd_event((byte)Keys.Divide,0,0,0); //key down keybd_event((byte)Keys.Divide,0,2,0); //key up break; } case "AlphabeticStateNo": { //delete the first letter keybd_event((byte)Keys.Back,0,0,0); //key down keybd_event((byte)Keys.Back,0,2,0); //key up //write the replacement letter string str1=firstRecognition; //fix miss recognition switch(firstRecognition) { case "a": str1="h"; break; case "b": str1="d"; break; case "c": str1="t"; break; case "d": str1="p"; break; case "f": str1="x"; break; case "h": str1="f"; break; case "m": str1="n"; break; case "n": str1="l"; break; case "l": str1="m"; break; case "p": str1="v"; break; case "u": str1="q"; break; case "v": str1="t"; break; case "e": str1="b"; break; case "j": str1="k"; break; } firstRecognition=str1; str1=str1.ToUpper(); keybd_event((byte)(str1[0]),0,0,0); //key down keybd_event((byte)(str1[0]),0,2,0); //key up break; } //else press the key (probably a menu ...) default: { string str1=e.PhraseInfo.Rule.Name; str1=str1.ToUpper(); keybd_event((byte)(str1[0]),0,0,0); //key down keybd_event((byte)(str1[0]),0,2,0); //key up //could be submenu (hook it) hookSubmenu(e.PhraseInfo.Rule.Name[0].ToString()); break; } } } //if not recognized ... else { //Only if agent enabled if (menuItem14.Checked==true) { //animate character agent1.Play("Decline"); } } }
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 static void AddRootNode( TreeView tree, ref int imageCount, ImageList imageList, ShellFolder shellFolder, bool getIcons ) { Shell32.Shell shell32 = new Shell32.ShellClass(); Shell32.Folder shell32Folder = shell32.NameSpace( shellFolder ); Shell32.FolderItems items = shell32Folder.Items(); tree.Nodes.Clear(); TreeNode desktop = new TreeNode( "Desktop", 0, 0 ); // Added in version 1.11 // add a FolderItem object to the root (Desktop) node tag that corresponds to the DesktopDirectory namespace // This ensures that the GetSelectedNodePath will return the actual Desktop folder path when queried. // There's possibly a better way to create a Shell32.FolderItem instance for this purpose, // but I surely don't know it Shell32.Folder dfolder = shell32.NameSpace( ShellFolder.DesktopDirectory ); foreach( Shell32.FolderItem fi in dfolder.ParentFolder.Items() ) { if( fi.Name == dfolder.Title ) { desktop.Tag = fi; break; } } // Add the Desktop root node to the tree tree.Nodes.Add( desktop ); // [xiperware] Get FolderItem that represents Recycle Bin Shell32.Folder recFolder = shell32.NameSpace( ShellFolder.RecycleBin ); Shell32.FolderItem recycle = null; foreach( Shell32.FolderItem fi in recFolder.ParentFolder.Items() ) { if( fi.Name == recFolder.Title ) { recycle = fi; break; } } // [xiperware] Get FolderItem that represents My Network Places Shell32.Folder netFolder = shell32.NameSpace( ShellFolder.NetworkNeighborhood ); Shell32.FolderItem mynetwork = null; foreach( Shell32.FolderItem fi in netFolder.ParentFolder.Items() ) { if( fi.Name == netFolder.Title ) { mynetwork = fi; break; } } // iterate through the Desktop namespace and populate the first level nodes foreach( Shell32.FolderItem item in items ) { if( !item.IsFolder ) continue; // this ensures that desktop shortcuts etc are not displayed if( item.IsBrowsable ) continue; // [xiperware] exclude zip files if( recycle != null && item.Path == recycle.Path ) continue; // [xiperware] skip recycle bin TreeNode tn = AddTreeNode( item, ref imageCount, imageList, getIcons ); desktop.Nodes.Add( tn ); if( mynetwork != null && item.Path == mynetwork.Path ) // [xiperware] skip my network places subdirs { tree.Tag = tn; // store node in tag continue; } CheckForSubDirs( tn, imageList ); } }
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); }