Esempio n. 1
0
        private void Set_Click(object sender, EventArgs e)
        {
            Folder_Error.Clear();
            Info.Clear();
            if (Icone_textBox.Text == "")
            {
                Folder_Error.SetIconPadding(Set, 0);
                Folder_Error.SetError(Set, "You must selcet icon first");
            }
            else
            {
                if (!Directory.Exists(Folder_textBox.Text))
                {
                    MessageBox.Show(this, @"Invalid Folder Path", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (!Exists(Icone_textBox.Text))
                {
                    MessageBox.Show(this, @"Invalid Icon Path", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var        filePaths     = Directory.GetFiles(Folder_textBox.Text);
                    var        iconfile      = "";
                    var        ini           = $@"{Folder_textBox.Text}\desktop.ini";
                    const uint fcsForcewrite = 0x00000002;
                    if (Folder_textBox.Text.Length <= 0)
                    {
                        return;
                    }
                    if (Exists(ini))
                    {
                        var inif = new IniFile(ini);
                        iconfile = inif.Read(".ShellClassInfo", "IconResource");
                        iconfile = iconfile.Substring(0, iconfile.Length - 2);
                    }
                    foreach (var filePath in filePaths)
                    {
                        var extension = GetExtension(filePath);
                        if (extension == null || !extension.Equals(".ini") && !extension.Equals(".ico"))
                        {
                            continue;
                        }

                        if (extension.Equals(".ico"))
                        {
                            if (!GetFileName(iconfile).Equals(GetFileName(filePath)))
                            {
                                continue;
                            }
                            try
                            {
                                Delete(filePath);
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine(exception);
                            }
                        }

                        else if (extension.Equals(".ini"))
                        {
                            var fileName = GetFileName(filePath);
                            if (fileName == null || !fileName.Equals("desktop.ini"))
                            {
                                continue;
                            }
                            try
                            {
                                Delete(filePath);
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine(exception);
                            }
                        }
                    }
                    var    changeExtension = ChangeExtension(GetFileName(Icone_textBox.Text), "ico");
                    var    tmpIcon         = $@"{Folder_textBox.Text}\{changeExtension}";
                    string iconS;
                    if (Exists(tmpIcon))
                    {
                        iconS = tmpIcon;
                    }

                    else
                    {
                        var extension = GetExtension(Icone_textBox.Text);
                        var file      = GetFileNameWithoutExtension(Icone_textBox.Text);
                        var tempPath  = GetTempPath();
                        //var tmpSource = ChangeExtension($@"{tempPath}{file + _mRnd}{extension}", "ico");
                        var    tmpSource  = ChangeExtension($@"{tempPath}{file}{extension}", "ico");
                        var    tmpSource2 = GetTempPath() + ChangeExtension(GetFileName(Icone_textBox.Text), "ico");
                        string sourceFile;
                        if (Exists(tmpSource))
                        {
                            sourceFile = tmpSource;
                        }
                        else if (Exists(tmpSource2))
                        {
                            sourceFile = tmpSource2;
                        }
                        else
                        {
                            sourceFile = Icone_textBox.Text;
                        }
                        iconS = $@"{Folder_textBox.Text}\{GetFileName(sourceFile)}";
                        Copy(sourceFile, iconS, true);
                    }

                    if (!Exists(iconS))
                    {
                        return;
                    }
                    var myFolderIcon = new FolderIcon(Folder_textBox.Text);
                    myFolderIcon.CreateFolderIcon(iconS);
                    SetAttributes(iconS, GetAttributes(iconS) | FileAttributes.Hidden);
                    SetAttributes(iconS, GetAttributes(iconS) | FileAttributes.System);
                    const uint fcsmIconfile   = 0x00000010;
                    var        folderSettings = new Lpshfoldercustomsettings
                    {
                        dwSize      = (uint)iconS.Length,
                        dwMask      = fcsmIconfile,
                        pszIconFile = GetFileName(iconS),
                        cchIconFile = 0,

                        iIconIndex = 0
                    };

                    SHGetSetFolderCustomSettings(ref folderSettings, Folder_textBox.Text, fcsForcewrite);
                    Process.Start(@"C:\Windows\System32\ie4uinit.exe", @"-show");
                    MessageBox.Show(this, @"Done", @"OK");
                    Folder_textBox.Text = "";
                    Icone_textBox.Text  = "";
                    Size = new Size(388, 282);
                    pictureBox1.Location              = new Point(50, 103);
                    Reset_Folder.Location             = new Point(193, 208);
                    Set.Location                      = new Point(275, 208);
                    TV_radioButton.CheckedChanged    -= TV_radioButton_CheckedChanged;
                    TV_radioButton.Checked            = false;
                    TV_radioButton.CheckedChanged    += TV_radioButton_CheckedChanged;
                    Movie_radioButton.CheckedChanged -= Movie_radioButton_CheckedChanged;
                    Movie_radioButton.Checked         = false;
                    Movie_radioButton.CheckedChanged += Movie_radioButton_CheckedChanged;
                    Movie_radioButton.Visible         = false;
                    TV_radioButton.Visible            = false;
                    if (pictureBox1.Image == null)
                    {
                        return;
                    }
                    pictureBox1.Image.Dispose();
                    pictureBox1.Image = null;
                }
            }
        }
Esempio n. 2
0
 private static extern uint SHGetSetFolderCustomSettings(ref Lpshfoldercustomsettings pfcs, string pszPath, uint dwReadWrite);