Exemplo n.º 1
0
        //删除样式文件
        private void CLearStyle(object sender, EventArgs e)
        {
            var mb = MessageBox.Show("此操作将会删除程序的所有样式文件\n并将磁贴磁贴还原为默认样式\n确认继续你的操作?", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

            if (mb == DialogResult.OK)
            {
                string  tileName = txtNameView.Text;
                TileXml tileXml  = new TileXml(myExePath);
                try
                {
                    if (File.Exists(tileXml.XmlPath))
                    {
                        File.Delete(tileXml.XmlPath);
                    }
                    if (File.Exists(tileXml.Square150x150Logo))
                    {
                        File.Delete(tileXml.Square150x150Logo);
                    }
                    if (File.Exists(tileXml.Square70x70Logo))
                    {
                        File.Delete(tileXml.Square70x70Logo);
                    }
                    if (File.Exists(tileXml.Square44x44Logo))
                    {
                        File.Delete(tileXml.Square44x44Logo);
                    }

                    Shortcut shortcut = new Shortcut();
                    if (cmbCommand.SelectedIndex == 0)
                    {
                        shortcut.CreateShortcut(myExePath, tileName, iconPath, iconIndex, false);
                    }
                    else
                    {
                        shortcut.CreateShortcut(myExePath, tileName, iconPath, iconIndex, true);
                    }
                }
                catch (Exception) { }

                if (!File.Exists(tileXml.XmlPath))
                {
                    new FormMyMessageBox("磁贴样式文件已删除,磁贴已还原为默认样式").Show();
                }
                else
                {
                    new FormMyMessageBox("删除失败,请尝试手动删除程序安装路径下的\n程序同名的.VisualElementsManifest.xml文件\n以及TileBeautify文件夹").Show();
                    Process.Start("explorer", "/select,\"" + tileXml.XmlPath + "\"");
                }
            }
        }
Exemplo n.º 2
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);
            }
        }