Exemple #1
0
        //生成样式文件
        private void SaveStyle(object sender, EventArgs e)
        {
            string tileName = txtNameView.Text;

            if (cmbCommand.SelectedIndex == 1)
            {
                if (tileName == "我的网址")
                {
                    MessageBox.Show("请更改你的磁贴名称", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    ReplaceName(null, null);
                    return;
                }

                var di = new DirectoryInfo(urlFolder);
                foreach (var fi in di.GetFiles())
                {
                    string fileName = Path.GetFileNameWithoutExtension(fi.FullName);
                    if (tileName == fileName)
                    {
                        string iniPath = urlFolder + "\\" + fileName + ".ini";
                        string urlPath = File.ReadAllText(iniPath, Encoding.Default);
                        var    mb      = MessageBox.Show("已存在同名文件URL磁贴程序,确认覆盖?" +
                                                         "\n链接:" + urlPath, "错误提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

                        if (mb == DialogResult.OK)
                        {
                            File.Delete(fi.FullName);
                            File.Delete(iniPath);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                ReplaceUrlFileName();
            }

            TileXml tileXml = new TileXml(myExePath)
            {
                BackgroundColor             = txtCodeView.Text,
                ForegroundText              = (cmbFontColor.SelectedIndex == 1) ? "dark" : "light",
                ShowNameOnSquare150x150Logo = (!chkShowName.Checked) ? "off" : "on"
            };
            string picFolder = tileXml.ExeFolder + MyName;
            string picPath   = picFolder + "\\" + tileXml.ExeName + ".png";

            if (cmbTileShowMode.SelectedIndex == 1)
            {
                if (chkUseEditedPic.Checked == true)
                {
                    string shortPicPath = MyName + "\\" + tileXml.ExeName + ".png";
                    tileXml.Square150x150Logo = shortPicPath;
                    tileXml.Square70x70Logo   = shortPicPath;
                    tileXml.Square44x44Logo   = shortPicPath;
                }
                else
                {
                    tileXml.Square150x150Logo = tileXml.ReadXml("Square150x150Logo");
                    tileXml.Square70x70Logo   = tileXml.ReadXml("Square70x70Logo");
                    tileXml.Square44x44Logo   = tileXml.ReadXml("Square44x44Logo");
                }
            }
            else
            {
                tileXml.Square150x150Logo = string.Empty;
                tileXml.Square70x70Logo   = string.Empty;
                tileXml.Square44x44Logo   = string.Empty;
            }

            try {
                if (chkUseEditedPic.Checked == true)
                {
                    Directory.CreateDirectory(picFolder);
                    File.SetAttributes(picFolder, FileAttributes.Hidden);
                    picEditedView.Image.Save(picPath, ImageFormat.Png);
                }
                if (cmbTileShowMode.SelectedIndex == 0)
                {
                    if (Directory.Exists(picFolder))
                    {
                        if (File.Exists(picPath))
                        {
                            File.Delete(picPath);
                            //文件夹中没有文件时删除
                            if (Directory.GetDirectories(picFolder).Length <= 0 && Directory.GetFiles(picFolder).Length <= 0)
                            {
                                Directory.Delete(picFolder);
                            }
                        }
                    }
                }
                tileXml.WriteXml(tileXml.XmlPath);
                Shortcut shortcut = new Shortcut();
                if (cmbCommand.SelectedIndex == 0)
                {
                    shortcut.CreateShortcut(myExePath, tileName, iconPath, iconIndex, false);
                }
                else
                {
                    shortcut.CreateShortcut(myExePath, tileName, iconPath, iconIndex, true);
                }
                MessageBox.Show("已成功修改程序磁贴样式,请手动将其固定到开始屏幕", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception) {
                MessageBox.Show("无法在程序目录写入样式文件\n可能为开启了自我保护的安全软件", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }