Exemplo n.º 1
0
        public static SpecialFolder Create(string parentpath, string alias)
        {
            DirectoryInfo parentdir = new DirectoryInfo(parentpath);
            int thisid = 0;
            foreach (DirectoryInfo dir in parentdir.GetDirectories())
            {
                if (dir.Name.StartsWith("spf_"))
                {
                    thisid++;
                }
            }
            DirectoryInfo count = new DirectoryInfo(parentdir.FullName + @"\spf_" + thisid.ToString());
            while (count.Exists)
            {
                thisid++;
            }
            DirectoryInfo cont = new DirectoryInfo(parentdir.FullName + @"\spf_" + thisid.ToString());
            cont.Create();
            FileInfo magic = new FileInfo(cont.FullName + @"\desktop.ini");
            FileAttributes fa = magic.Attributes;
            FileStream fs = magic.OpenWrite();
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(@"[" + @".ShellClassInfo" + @"]");
            sw.WriteLine(@"LocalizedResourceName=" + alias);
            sw.Flush();
            sw.Close();
            fs.Close();
            FileInfo mer = new FileInfo(cont.FullName + @"\desktop.ini");
            mer.Attributes = FileAttributes.Hidden | FileAttributes.Archive | FileAttributes.System;
            Common.LPSHFOLDERCUSTOMSETTINGS FolderSettings = new Common.LPSHFOLDERCUSTOMSETTINGS();
            FolderSettings.dwMask = 0x10;
            FolderSettings.pszIconFile = @"X:\Windows\system32\SHELL32.dll";
            FolderSettings.iIconIndex = 3;

            UInt32 FCS_READ = 0x00000001;
            UInt32 FCS_FORCEWRITE = 0x00000002;
            UInt32 FCS_WRITE = FCS_READ | FCS_FORCEWRITE;

            string pszPath = cont.FullName;
            UInt32 HRESULT = Common.SHGetSetFolderCustomSettings(ref FolderSettings, pszPath, FCS_WRITE);
            Common.RefreshIconCache();
            return new SpecialFolder(cont.FullName);
        }
Exemplo n.º 2
0
        public void Rename(string newname)
        {
            FileInfo magic = new FileInfo(dI.FullName + @"\desktop.ini");
            FileAttributes fa = magic.Attributes;
            FileStream fs = new FileStream(magic.FullName, FileMode.Truncate);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(@"[" + @".ShellClassInfo" + @"]");
            sw.WriteLine(@"LocalizedResourceName=" + newname);
            sw.Flush();
            sw.Close();
            fs.Close();
            FileInfo mer = new FileInfo(dI.FullName + @"\desktop.ini");
            mer.Attributes = FileAttributes.Hidden | FileAttributes.Archive | FileAttributes.System;
            Common.LPSHFOLDERCUSTOMSETTINGS FolderSettings = new Common.LPSHFOLDERCUSTOMSETTINGS();
            FolderSettings.dwMask = 0x10;
            FolderSettings.pszIconFile = @"X:\Windows\system32\SHELL32.dll";
            FolderSettings.iIconIndex = 3;

            UInt32 FCS_READ = 0x00000001;
            UInt32 FCS_FORCEWRITE = 0x00000002;
            UInt32 FCS_WRITE = FCS_READ | FCS_FORCEWRITE;

            string pszPath = dI.FullName;
            UInt32 HRESULT = Common.SHGetSetFolderCustomSettings(ref FolderSettings, pszPath, FCS_WRITE);
            Common.RefreshIconCache();
        }