public static FileSystemInfoEx ResolveSymLink(this FileSystemInfoEx info) { var path = info.FullName; string directory = Path.GetDirectoryName(path); string file = Path.GetFileName(path); Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder folder = shell.NameSpace(directory); Shell32.FolderItem folderItem = folder.ParseName(file); Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; FileSystemInfoEx ret = null; if (Path.GetDirectoryName(link.Path) == link.Path) { ret = new DirectoryInfoEx(link.Path); } else { ret = new FileInfoEx(link.Path); } return(ret); }
public static void SetLnkTarget(string shortcutFullPath, string newTarget) { try { // Load the shortcut. Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder folder = (Shell32.Folder)shell.NameSpace(Path.GetDirectoryName(shortcutFullPath)); Shell32.FolderItem folderItem = folder.Items().Item(Path.GetFileName(shortcutFullPath)); Shell32.ShellLinkObject currentLink = (Shell32.ShellLinkObject)folderItem.GetLink; //Assign the new path here. This value is not read-only. currentLink.Path = newTarget; // Save the link to commit the changes. currentLink.Save(); } catch (Exception Ex) { Console.WriteLine(Ex.Message); } }
private void extendProperties() { //hakee jokaiseen haettuun tiedostoon kaikki sen ylimääräiseset tiedostoinformaatiot string prevFilePath = ""; Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder folder = null; foreach (Dictionary <string, string> item in fileInfo) { string filePath = item["FullName"]; string name = Path.GetDirectoryName(filePath); if (name != prevFilePath) { folder = shell.NameSpace(name); prevFilePath = name; } Shell32.FolderItem folderItem = folder.ParseName(Path.GetFileName(item["FullName"])); for (int i = 0; i < short.MaxValue; i++) { string propValue = folder.GetDetailsOf(folderItem, i); if (!propValue.Equals("")) { string propName = folder.GetDetailsOf(null, i); if (String.IsNullOrEmpty(propName)) { break; } if (!propName.Equals("Name") && !propName.Equals("Path")) { item.Add(propName, propValue); } } } } }
public override void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node) { if (!EnableContextMenu) { return; } // Shell32.FolderItem fi = node.Tag as Shell32.FolderItem; if (fi == null) { return; } // foreach (Shell32.FolderItemVerb verb in fi.Verbs()) { if (verb.Name.Length == 0) { continue; } // MenuItemShellVerb item = new MenuItemShellVerb(verb); helper.TreeView.ContextMenu.MenuItems.Add(item); } }
protected void btnSaveMedia_Click(object sender, EventArgs e) { Accomodation_ID = new Guid(Request.QueryString["Hotel_Id"]); var resultAcco = AccSvc.GetHotelDetails(Accomodation_ID); MediaAbsPath = System.Configuration.ConfigurationManager.AppSettings["MediaAbsPath"] + resultAcco[0].ProductCategorySubType + "/" + resultAcco[0].CompanyHotelID.ToString() + "/"; MediaAbsUrl = System.Configuration.ConfigurationManager.AppSettings["MediaAbsURL"] + resultAcco[0].ProductCategorySubType + "/" + resultAcco[0].CompanyHotelID.ToString() + "/"; if (Page.IsValid) { if (btnSaveMedia.CommandName == "AddMedia") { MDMSVC.DC_Accommodation_Media newObj = new MDMSVC.DC_Accommodation_Media { Accommodation_Media_Id = Guid.NewGuid(), Category = (ddlFileCategory.SelectedIndex == 0 ? null : ddlFileCategory.SelectedItem.Text), Description = txtDescription.Text, //FileFormat = (ddlFileFormat.SelectedIndex == 0 ? null : ddlFileFormat.SelectedItem.Text), // MediaID = txtMediaID.Text, MediaType = (ddlMediaType.SelectedIndex == 0 ? null : ddlMediaType.SelectedItem.Text), Media_Position = Convert.ToInt32(txtMediaPosition.Text), RoomCategory = (ddlRoomCategory.SelectedIndex == 0 ? null : ddlRoomCategory.SelectedItem.Text), SubCategory = (ddlSubCategory.SelectedIndex == 0 ? null : ddlSubCategory.SelectedItem.Text), Accommodation_Id = Guid.Parse(Request.QueryString["Hotel_Id"]), ValidFrom = DateTime.ParseExact(txtValidFrom.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture), ValidTo = DateTime.ParseExact(txtValidTo.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture), IsActive = true, Create_Date = DateTime.Now, Create_User = System.Web.HttpContext.Current.User.Identity.Name, MediaFileMaster = (ddlFileMaster.SelectedIndex == 0 ? null : ddlFileMaster.SelectedItem.Text) }; if (!string.IsNullOrWhiteSpace(hdnMediaName.Value)) { //if(!string.IsNullOrWhiteSpace(txtMediaName.Text)) //{ // newObj.MediaName = System.IO.Path.GetFileNameWithoutExtension(txtMediaName.Text) + System.IO.Path.GetExtension(hdnMediaName.Value); // newObj.Media_Path = MediaAbsPath + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(txtMediaName.Text) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value); // newObj.Media_URL = MediaAbsUrl + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(txtMediaName.Text) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value); //} //else //{ newObj.MediaName = hdnMediaName.Value; newObj.Media_Path = MediaAbsPath + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(hdnMediaName.Value) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value); newObj.Media_URL = MediaAbsUrl + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(hdnMediaName.Value) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value); newObj.FileFormat = System.IO.Path.GetExtension(hdnMediaName.Value); //} } else { newObj.MediaName = string.Empty; newObj.Media_Path = string.Empty; newObj.Media_URL = string.Empty; newObj.FileFormat = string.Empty; } string sMediaPathToCheck = MediaAbsPath + hdnMediaName.Value; if (!string.IsNullOrWhiteSpace(hdnMediaName.Value)) { if (!System.IO.Directory.Exists(MapPath(MediaAbsPath))) { System.IO.Directory.CreateDirectory(MapPath(MediaAbsPath)); } if (System.IO.File.Exists(MapPath(newObj.Media_Path))) { System.IO.File.Delete(MapPath(newObj.Media_Path)); } FileInfo file = new FileInfo(MapPath(sMediaPathToCheck)); file.MoveTo(file.Directory.FullName + "\\" + System.IO.Path.GetFileName(MapPath(newObj.Media_Path))); //System.Drawing.Image _img = ThumbnailImage(System.Drawing.Image.FromFile(file.Directory.FullName + "\\" + System.IO.Path.GetFileName(MapPath(newObj.Media_Path))), 90, 60); //file.MoveTo(file.Directory.FullName + "\\" + System.IO.Path.GetFileName(MapPath(newObj.Media_Path))); } if (AccSvc.AddAccomodation_MediaDetails(newObj)) { //Auto insert file attributes try { //Shell32.Shell shell = new Shell32.Shell(); Type t = Type.GetTypeFromProgID("Shell.Application"); dynamic shell = Activator.CreateInstance(t); Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(MapPath(newObj.Media_Path))); Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(MapPath(newObj.Media_Path))); List <string> arrHeaders = new List <string>(); //Get file attribute list for consideratioins string strAttributeslist = Convert.ToString(ConfigurationManager.AppSettings["MediaAttributes"]); List <string> _lstAttributes = strAttributeslist.Split(',').ToList(); for (int i = 0; i < short.MaxValue; i++) { string header = objFolder.GetDetailsOf(null, i); if (String.IsNullOrEmpty(header)) { break; } arrHeaders.Add(header); } for (int i = 0; i < arrHeaders.Count; i++) { string AttrTypr = arrHeaders[i]; if (!_lstAttributes.Contains(AttrTypr)) { continue; } string AttrVal = objFolder.GetDetailsOf(folderItem, i); if (!string.IsNullOrWhiteSpace(AttrVal)) { MDMSVC.DC_Accomodation_Media_Attributes newObjAttr = new MDMSVC.DC_Accomodation_Media_Attributes { Accomodation_Media_Attributes_Id = Guid.NewGuid(), Accomodation_Media_Id = newObj.Accommodation_Media_Id, AttributeType = AttrTypr, AttributeValue = AttrVal, IsActive = true, Create_Date = DateTime.Now, IsSystemAttribute = true, Create_User = System.Web.HttpContext.Current.User.Identity.Name }; AccSvc.AddAccomodation_MediaAttributesDetails(newObjAttr); } } } catch { } BindMedia(); ClearMediaControls(); hdnFlag.Value = "true"; BootstrapAlert.BootstrapAlertMessage(dvMsg, "Media has been added successfully", BootstrapAlertType.Success); } else { BootstrapAlert.BootstrapAlertMessage(dvMsg, "Error Occurred", BootstrapAlertType.Warning); } } else if (btnSaveMedia.CommandName == "UpdateMedia") { Accomodation_ID = new Guid(Request.QueryString["Hotel_Id"]); Guid myRow_Id = Guid.Parse(gvMedia.SelectedDataKey.Value.ToString()); int intMediaPosition = 0; if (Int32.TryParse(txtMediaPosition.Text, out intMediaPosition)) { intMediaPosition = Convert.ToInt32(txtMediaPosition.Text); } MDMSVC.DC_Accommodation_Media newObj = new MDMSVC.DC_Accommodation_Media { Accommodation_Media_Id = myRow_Id, Category = (ddlFileCategory.SelectedIndex == 0 ? null : ddlFileCategory.SelectedItem.Text), MediaFileMaster = (ddlFileMaster.SelectedIndex == 0 ? null : ddlFileMaster.SelectedItem.Text), Description = txtDescription.Text, //FileFormat = (ddlFileFormat.SelectedIndex == 0 ? null : ddlFileFormat.SelectedItem.Text), MediaType = (ddlMediaType.SelectedIndex == 0 ? null : ddlMediaType.SelectedItem.Text), Media_Position = intMediaPosition, RoomCategory = (ddlRoomCategory.SelectedIndex == 0 ? null : ddlRoomCategory.SelectedItem.Text), SubCategory = (ddlSubCategory.SelectedIndex == 0 ? null : ddlSubCategory.SelectedItem.Text), ValidFrom = DateTime.ParseExact(txtValidFrom.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture), ValidTo = DateTime.ParseExact(txtValidTo.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture), IsActive = true, Edit_Date = DateTime.Now, Edit_User = System.Web.HttpContext.Current.User.Identity.Name, }; if (AccSvc.UpdateAccomodation_MediaDetails(newObj)) { BindMedia(); ClearMediaControls(); hdnFlag.Value = "true"; BootstrapAlert.BootstrapAlertMessage(dvMsg, "Media has been updated successfully", BootstrapAlertType.Success); } else { BootstrapAlert.BootstrapAlertMessage(dvMsg, "Error Occurred", BootstrapAlertType.Warning); } } dvBrowseMedia.Visible = true; UpMediaModal.Update(); } //hdnFlag.Value = "true"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop2" + DateTime.Today.Ticks.ToString(), "javascript:closeMediaModal();", true); // ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop2", "javascript:closeMediaModal();", true); }
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); } }
/// <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(); }
/// <summary> /// Do we have to add a dummy node (+ sign) /// </summary> protected virtual bool IsFolderWithChilds(Shell32.FolderItem fi) { return(_showAllShellObjects || (fi.IsFileSystem && fi.IsFolder && !fi.IsBrowsable)); }
private void MusixmatchUpdateToolStripMenuItem_Click(object sender, EventArgs e) { try { string[] files = Directory.GetFiles(path, "*.mp3", SearchOption.AllDirectories); errorList = "No data for the following: "; for (int i = 0; i < files.Length; i++) { FileInfo file = new FileInfo(files[i]); var strFileName = file.DirectoryName + "\\" + file.Name; ShellObject song = ShellObject.FromParsingName(strFileName); string artist = GetValue(song.Properties.GetProperty(SystemProperties.System.Music.AlbumArtist)); string title = GetValue(song.Properties.GetProperty(SystemProperties.System.Title)); if (artist != "" && title != "") { var year = GetValue(song.Properties.GetProperty(SystemProperties.System.Media.Year)); string album = GetValue(song.Properties.GetProperty(SystemProperties.System.Music.AlbumTitle)); Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName)); Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName)); var genre = objFolder.GetDetailsOf(folderItem, 16); if (year.ToString() == "" || Convert.ToInt16(year) == 0 || album == "" || genre.ToString() == "") { var fileshell = ShellFile.FromFilePath(strFileName); ShellPropertyWriter propertyWriter = fileshell.Properties.GetPropertyWriter(); try { var trackJSON = SingleEdit.MusixmatchGet(artist, title); if (trackJSON.Item1 != null) { try { string yearMM = "";//trackJSON.Item1.FirstReleaseDate.Year.ToString(); if ((year.ToString() == "" || Convert.ToInt16(year) == 0) && yearMM != "" && Convert.ToInt16(yearMM) <= Convert.ToInt16(DateTime.Now.Year) && Convert.ToInt16(yearMM) > 1900) { propertyWriter.WriteProperty(SystemProperties.System.Media.Year, new int[] { Convert.ToInt16(yearMM) }); } } catch { errorList += Environment.NewLine + "Year error in: " + file.Name; } try { string albumMM = trackJSON.Item1.AlbumName.ToString(); if (album == "" && albumMM != "") { propertyWriter.WriteProperty(SystemProperties.System.Music.AlbumTitle, new string[] { albumMM }); } } catch { errorList += Environment.NewLine + "Album error in: " + file.Name; } if (genre.ToString() == "") { try { string genreMM = trackJSON.Item1.PrimaryGenres.MusicGenreList[0].MusicGenre.MusicGenreName.ToString(); if (genreMM.ToString() != "") { propertyWriter.WriteProperty(SystemProperties.System.Music.Genre, new string[] { genreMM }); } } catch (IndexOutOfRangeException) { errorList += Environment.NewLine + "Genre error in: " + file.Name; } } } else if (trackJSON.Item2 == true) { break; } else { errorList += Environment.NewLine + file.Name; } } finally { propertyWriter.Close(); } } } progressBar1.Value = Convert.ToInt32(100 * (i + 1) / files.Length); if (i == files.Length - 1) { progressBar1.Value = 100; } } ErrorList errorForm = new ErrorList(errorList); errorForm.ShowDialog(); } catch (FileNotFoundException) { System.Windows.Forms.MessageBox.Show("Files not found exception!", "Message"); } }
public static void Main(string[] args) { string[] supportedTypes = { ".mp4", ".mov", ".avi" }; if (args.Length < 1) { Console.WriteLine("Usage: GetNumFrames filepath"); return; } if (Array.IndexOf(supportedTypes, Path.GetExtension(args[0]).ToLower()) == -1) { Console.WriteLine("Usage: GetNumFrames filepath (type must be supported: {0})", supportedTypes.ToString()); return; } Console.OutputEncoding = Encoding.UTF8; List <string> arrHeaders = new List <string>(); List <int> arrIndeces = new List <int>(); Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder objFolder; string fullPath = Path.GetFullPath(args[0]); //objFolder = shell.NameSpace(Path.GetDirectoryName(args[0])); objFolder = shell.NameSpace(Path.GetDirectoryName(fullPath)); for (int i = 0; i < short.MaxValue; i++) { string header = objFolder.GetDetailsOf(null, i); //if (String.IsNullOrEmpty(header)) // break; //arrHeaders.Add(header); if (!String.IsNullOrEmpty(header)) { arrHeaders.Add(header); arrIndeces.Add(i); } } //foreach (Shell32.FolderItem2 item in objFolder.Items()) Shell32.FolderItem item = objFolder.ParseName(Path.GetFileName((args[0]))); if (true) { string lenString = ""; int frameRate = 0; int secs = 0; int i = 0; for (i = 0; i < arrHeaders.Count; i++) { //Console.WriteLine("{0}\t{1}: {2}", arrIndeces[i], arrHeaders[i], objFolder.GetDetailsOf(item, arrIndeces[i])); if (arrIndeces[i] == 27) // length { lenString = objFolder.GetDetailsOf(item, arrIndeces[i]); string[] lenTokens = lenString.Split(':'); secs = int.Parse(lenTokens[2]) + (60 * int.Parse(lenTokens[1])) + (60 * 60 * int.Parse(lenTokens[0])); } else if (arrIndeces[i] == 305) //frame rate { string fr = objFolder.GetDetailsOf(item, arrIndeces[i]); string fr2 = fr.Substring(1); int j = 0; for (j = 0; j < fr2.Length; j++) { if ((fr2[j] < '0') || (fr2[j] > '9')) { break; } } int val = 0; int.TryParse(fr.Substring(1, j), out val); frameRate = val; //Console.WriteLine("frame rate {0}", val); } } int frames = 0; switch (frameRate) { case 29: frames = (int)((float)secs * 29.97); break; case 59: frames = (int)((float)secs * 59.94); break; default: frames = (int)((float)secs * frameRate); break; } Console.WriteLine("{0}", frames); //Console.WriteLine("{0}\t{1}: {2}", i, arrHeaders[i], objFolder.GetDetailsOf(item, 281)); } }
/// <summary> /// Get image resolution. /// </summary> private static List <ExifInfo> GetImageResolutionWidthAndHeight(Shell32.Folder objFolder, Shell32.FolderItem folderItem) { var imageResolutionInfo = new List <ExifInfo>(); // 水平解像度 var propertyValue = objFolder.GetDetailsOf(folderItem, 175); var propertyText = "水平解像度"; imageResolutionInfo.Add(new ExifInfo(propertyText, propertyValue)); // 垂直解像度 propertyValue = objFolder.GetDetailsOf(folderItem, 177); propertyText = "垂直解像度"; imageResolutionInfo.Add(new ExifInfo(propertyText, propertyValue)); return(imageResolutionInfo); }
/// <summary> /// Get image width and height. /// </summary> private static List <ExifInfo> GetImageWidthAndHeight(Shell32.Folder objFolder, Shell32.FolderItem folderItem) { var imageWidthAndHeightInfo = new List <ExifInfo>(); // 幅 var propertyValue = objFolder.GetDetailsOf(folderItem, 176); var propertyText = "幅"; imageWidthAndHeightInfo.Add(new ExifInfo(propertyText, propertyValue)); // 高さ propertyValue = objFolder.GetDetailsOf(folderItem, 178); propertyText = "高さ"; imageWidthAndHeightInfo.Add(new ExifInfo(propertyText, propertyValue)); return(imageWidthAndHeightInfo); }
private void testBtn_Click(object sender, EventArgs e) { // Write properties to file string filePath = @"C:\\Users\Solomon\\Pictures\\Test1.docx"; var file = ShellFile.FromFilePath(filePath); // Read and Write: string[] oldAuthors = file.Properties.System.Author.Value; string oldTitle = file.Properties.System.Title.Value; file.Properties.System.Comment.Value = "©COPYRIGHT DATAASGUARD"; file.Properties.System.Title.Value = "Seolhyun"; // Alternate way to Write: ShellPropertyWriter propertyWriter = file.Properties.GetPropertyWriter(); //propertyWriter.WriteProperty(SystemProperties.System.Comment, new string[] { "Comment" }); propertyWriter.Close(); // Read File extended properties List <string> arrHeaders = new List <string>(); List <Tuple <int, string, string> > attributes = new List <Tuple <int, string, string> >(); Shell32.Shell shell = new Shell32.Shell(); var strFileName = @"C:\Users\Solomon\Pictures\Test1.docx"; Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName)); Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName)); for (int i = 0; i < short.MaxValue; i++) { string header = objFolder.GetDetailsOf(null, i); if (String.IsNullOrEmpty(header)) { break; } arrHeaders.Add(header); } // The attributes list below will contain a tuple with attribute index, name and value // Once you know the index of the attribute you want to get, // you can get it directly without looping, like this: var Authors = objFolder.GetDetailsOf(folderItem, 20); for (int i = 0; i < arrHeaders.Count; i++) { var attrName = arrHeaders[i]; var attrValue = objFolder.GetDetailsOf(folderItem, i); var attrIdx = i; attributes.Add(new Tuple <int, string, string>(attrIdx, attrName, attrValue)); //if (i <= 5 || i == 10 || i == 21 || i == 24) //{ //Console.WriteLine("{0}\t{1}: {2}", i, attrName, attrValue); Console.WriteLine("{0}\t{1}: {2}", i + 1, attrName, attrValue); //} } Console.ReadLine(); }
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> /// Get shutter speed and aperture value. /// </summary> private static List <ExifInfo> GetFnumberAndShutterSpeed(Shell32.Folder objFolder, Shell32.FolderItem folderItem) { var shutterSpeedAndApertureInfo = new List <ExifInfo>(); // シャッター速度 var propertyValue = objFolder.GetDetailsOf(folderItem, 259); var propertyText = "シャッター速度"; shutterSpeedAndApertureInfo.Add(new ExifInfo(propertyText, propertyValue)); // 絞り値 propertyValue = objFolder.GetDetailsOf(folderItem, 260); propertyText = "絞り値"; shutterSpeedAndApertureInfo.Add(new ExifInfo(propertyText, propertyValue)); return(shutterSpeedAndApertureInfo); }
public MediaItem(string Path) { this.Path = Path; Folder = Shell.NameSpace(System.IO.Path.GetDirectoryName(Path)); FolderItem = Folder.ParseName(System.IO.Path.GetFileName(Path)); Execute(); UpdateContainingMedia(); //TraceProperties(); }
/// <summary> /// Get exposure program and white balance. /// </summary> private static List <ExifInfo> GetExposeModeAndWhiteBlance(Shell32.Folder objFolder, Shell32.FolderItem folderItem) { var exposeModeAndWhiteBlanceInfo = new List <ExifInfo>(); // 露出プログラム var propertyValue = objFolder.GetDetailsOf(folderItem, 258); var propertyText = "露出プログラム"; exposeModeAndWhiteBlanceInfo.Add(new ExifInfo(propertyText, propertyValue)); // ホワイトバランス propertyValue = objFolder.GetDetailsOf(folderItem, 275); propertyText = "ホワイトバランス"; exposeModeAndWhiteBlanceInfo.Add(new ExifInfo(propertyText, propertyValue)); return(exposeModeAndWhiteBlanceInfo); }
private void ChangeArtistsInfoToolStripMenuItem_Click(object sender, EventArgs e) { try { string[] files = Directory.GetFiles(path, "*.mp3", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { FileInfo file = new FileInfo(files[i]); if (NameCheck(file.Name) == "") { var fileshell = ShellFile.FromFilePath(file.DirectoryName + "\\" + file.Name); Shell32.Shell shell = new Shell32.Shell(); var strFileName = file.DirectoryName + "\\" + file.Name; Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName)); Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName)); var contrArtist = objFolder.GetDetailsOf(folderItem, 13); if (contrArtist == "" || contrArtist.Contains("ntitled") || contrArtist.Contains("various") || contrArtist.Contains("Various") || contrArtist.Contains("nknown") || contrArtist.Contains("http") || contrArtist.Contains("www.") || contrArtist.Contains(".com")) { string name = objFolder.GetDetailsOf(folderItem, 0); string[] newName = Regex.Split(name, "-"); string[] newest = Regex.Split(newName[0], "\\."); ShellPropertyWriter propertyWriter = fileshell.Properties.GetPropertyWriter(); try { if (newest.Length >= 2 && newest[1] != null) { propertyWriter.WriteProperty(SystemProperties.System.Music.Artist, new string[] { newest[1] }); } else if (newest.Length < 2) { } } finally { propertyWriter.Close(); } } ShellObject song = ShellObject.FromParsingName(strFileName); var albumArtist = GetValue(song.Properties.GetProperty(SystemProperties.System.Music.AlbumArtist)); if (albumArtist == "" || albumArtist.Contains("ntitled") || albumArtist.Contains("various") || albumArtist.Contains("Various") || albumArtist.Contains("nknown") || contrArtist.Contains("nknown") || contrArtist.Contains("http") || contrArtist.Contains("www.") || contrArtist.Contains(".com")) { string name = objFolder.GetDetailsOf(folderItem, 0); string[] newName = Regex.Split(name, "-"); string[] newest = Regex.Split(newName[0], "\\."); ShellPropertyWriter propertyWriter = fileshell.Properties.GetPropertyWriter(); try { if (newest.Length >= 2 && newest[1] != null) { propertyWriter.WriteProperty(SystemProperties.System.Music.AlbumArtist, new string[] { newest[1] }); } else if (newest.Length < 2) { } } finally { propertyWriter.Close(); } } } progressBar1.Value = Convert.ToInt32(100 * (i + 1) / files.Length); if (i == files.Length - 1) { progressBar1.Value = 100; } } } catch (FileNotFoundException) { System.Windows.Forms.MessageBox.Show("Files not found exception!", "Message"); } }
public static int GetNumFrames(string movFile) { List <string> arrHeaders = new List <string>(); List <int> arrIndeces = new List <int>(); Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder objFolder; string fullPath = Path.GetFullPath(movFile); //objFolder = shell.NameSpace(Path.GetDirectoryName(args[0])); objFolder = shell.NameSpace(Path.GetDirectoryName(fullPath)); for (int i = 0; i < short.MaxValue; i++) { string header = objFolder.GetDetailsOf(null, i); //if (String.IsNullOrEmpty(header)) // break; //arrHeaders.Add(header); if (!String.IsNullOrEmpty(header)) { arrHeaders.Add(header); arrIndeces.Add(i); } } //foreach (Shell32.FolderItem2 item in objFolder.Items()) Shell32.FolderItem item = objFolder.ParseName(Path.GetFileName((movFile))); if (true) { string lenString = ""; int frameRate = 0; int secs = 0; int i = 0; for (i = 0; i < arrHeaders.Count; i++) { //Console.WriteLine("{0}\t{1}: {2}", arrIndeces[i], arrHeaders[i], objFolder.GetDetailsOf(item, arrIndeces[i])); if (arrIndeces[i] == 27) // length { lenString = objFolder.GetDetailsOf(item, arrIndeces[i]); string[] lenTokens = lenString.Split(':'); secs = int.Parse(lenTokens[2]) + (60 * int.Parse(lenTokens[1])) + (60 * 60 * int.Parse(lenTokens[0])); } else if (arrIndeces[i] == 305) //frame rate { string fr = objFolder.GetDetailsOf(item, arrIndeces[i]); string fr2 = fr.Substring(1); int j = 0; for (j = 0; j < fr2.Length; j++) { if ((fr2[j] < '0') || (fr2[j] > '9')) { break; } } int val = 0; int.TryParse(fr.Substring(1, j), out val); frameRate = val; //Console.WriteLine("frame rate {0}", val); } } int frames = 0; switch (frameRate) { case 29: frames = (int)((float)secs * 29.97); break; case 59: frames = (int)((float)secs * 59.94); break; default: frames = (int)((float)secs * frameRate); break; } return(frames); } }
private void ProcessDesktopContext(MouseEventArgs e) { DesktopContext dct = new DesktopContext(snap); void handler(object snd, FormClosedEventArgs args) { int pick = dct.buttonIndex; dct.Dispose(); if (pick == 1) { if (!snap) { snap = true; // Snap all icons to grid. for (int i = 0; i < dm.IconCount(); i++) { DesktopIcon ico = dm.icons[i]; ico.target = GetSnapToGridPoint(ico); dm.icons[i] = ico; } } else { snap = false; } } else if (pick == 2) { // Create new icon. CreateIconWindow ciw = new CreateIconWindow(); ciw.Location = Cursor.Position; ciw.ShowDialog(); if (!ciw.IsConfirmed()) { return; } if (ciw.appdir.ToLower().EndsWith(".lnk")) { Shell32.Shell sh = new Shell32.Shell(); Shell32.Folder scf = sh.NameSpace(Path.GetDirectoryName(ciw.appdir)); Shell32.FolderItem item = scf.ParseName(Path.GetFileName(ciw.appdir)); if (item == null) { MessageBox.Show("Invalid .lnk file? null"); return; } if (!item.IsLink) { MessageBox.Show("Invalid .lnk file? nonlink"); //MessageBox.Show(item.Name + "\n" + item.IsLink + "\n" + item.Path + "\n" + item.Type); return; } Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)item.GetLink; DesktopIcon ico = new DesktopIcon(e.X, e.Y, lnk.Target.Path, dm) { name = ciw.name }; dm.AddIcon(ico); } else { DesktopIcon ico = new DesktopIcon(e.X, e.Y, ciw.appdir, dm) { name = ciw.name }; dm.AddIcon(ico); } ciw.Dispose(); } else if (pick == 3) { // Change wallpaper. OpenFileDialog ofd = new OpenFileDialog { CheckFileExists = true, Multiselect = false, Filter = "Image/Video Files (*.jpg, *.jpeg, *.png, *.gif, *.mp4)|*.jpg;*.jpeg;*.png;*.gif;*.mp4;" }; var res = ofd.ShowDialog(); if (res != DialogResult.OK) { ofd.Dispose(); return; } wp.SetWallpaper(runOnMonitor, ofd); return; } else if (pick == 4) { // Save SaveLayout(); return; } else if (pick == 5) { // Load if (!TryLoadLayout()) { MessageBox.Show("Couldn't load any existing layout files. Try saving first."); return; } return; } } dct.FormClosed += handler; dct.Show(); dct.Location = Cursor.Position; }
public static MP3File ReadWMATags(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 string[] allDetails = new string[34]; for (int index = 0; index < 34; index++) { try { allDetails[index] = folder.GetDetailsOf(folderItem, index).Trim(); } catch { continue; } } mp3File.ArtistName = folder.GetDetailsOf(folderItem, 16).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); }