예제 #1
0
        //根据xml内容填充信息
        private void FillInfo(string filePath, string fileNeme)
        {
            cmbTileShowMode.SelectedIndex = 0;
            cmbCommand.SelectedIndex      = 0;
            myExePath            = filePath;
            txtPathView.Text     = filePath;
            btnSaveStyle.Enabled = true;
            txtNameView.Text     = fileNeme;
            picIconView.Image    = Icon.ExtractAssociatedIcon(filePath).ToBitmap();
            iconIndex            = 0;
            iconPath             = filePath;
            ShowPic(filePath);

            if (picEditedView.Image != null || isAlreadyHasPic)
            {
                cmbTileShowMode.Enabled = true;
            }

            TileXml tileXml = new TileXml(filePath);

            if (!File.Exists(tileXml.XmlPath))
            {
                chkShowName.Checked        = true;
                cmbFontColor.SelectedIndex = 0;
                picColorView.BackColor     = ThemeColor.GetThemeColor();
                btnClearStyle.Enabled      = false;
            }
            else
            {
                chkShowName.Checked        = (tileXml.ShowNameOnSquare150x150Logo == "off") ? false : true;
                cmbFontColor.SelectedIndex = (tileXml.ForegroundText == "dark") ? 1 : 0;
                picColorView.BackColor     = ColorTranslator.FromHtml(tileXml.BackgroundColor);
                btnClearStyle.Enabled      = true;
            }
        }
예제 #2
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 + "\"");
                }
            }
        }
예제 #3
0
        //显示图片
        private void ShowPic(string filePath)
        {
            TileXml tileXml = new TileXml(filePath);

            if (!File.Exists(tileXml.XmlPath))
            {
                isAlreadyHasPic = false;
                UseIcoAsPic();
                return;
            }
            mightHasPic = tileXml.MightHasPic;
            string square150x150Logo = tileXml.Square150x150Logo;
            string square70x70Logo   = tileXml.Square70x70Logo;
            string square44x44Logo   = tileXml.Square44x44Logo;

            int num = 0;

            if (File.Exists(square150x150Logo))
            {
                num++;
            }
            if (File.Exists(square70x70Logo))
            {
                num += 2;
            }
            if (File.Exists(square44x44Logo))
            {
                num += 4;
            }

            if (num == 0)
            {
                isAlreadyHasPic = false;
                UseIcoAsPic();
                return;
            }
            else if (num == 1)
            {
                pic150x150View.ImageLocation = square150x150Logo;
                pic70x70View.ImageLocation   = square150x150Logo;
                pic44x44View.ImageLocation   = square150x150Logo;
            }
            else if (num == 2)
            {
                pic150x150View.ImageLocation = square70x70Logo;
                pic70x70View.ImageLocation   = square70x70Logo;
                pic44x44View.ImageLocation   = square70x70Logo;
            }
            else if (num == 3)
            {
                pic150x150View.ImageLocation = square150x150Logo;
                pic70x70View.ImageLocation   = square70x70Logo;
                pic44x44View.ImageLocation   = square70x70Logo;
            }
            else if (num == 4)
            {
                pic150x150View.ImageLocation = square44x44Logo;
                pic70x70View.ImageLocation   = square44x44Logo;
                pic44x44View.ImageLocation   = square44x44Logo;
            }
            else if (num == 5)
            {
                pic150x150View.ImageLocation = square150x150Logo;
                pic70x70View.ImageLocation   = square150x150Logo;
                pic44x44View.ImageLocation   = square44x44Logo;
            }
            else if (num == 6)
            {
                pic150x150View.ImageLocation = square70x70Logo;
                pic70x70View.ImageLocation   = square70x70Logo;
                pic44x44View.ImageLocation   = square44x44Logo;
            }
            else if (num == 7)
            {
                pic150x150View.ImageLocation = square150x150Logo;
                pic70x70View.ImageLocation   = square70x70Logo;
                pic44x44View.ImageLocation   = square44x44Logo;
            }
            isAlreadyHasPic = true;
            cmbTileShowMode.SelectedIndex = 1;
            pic150x150View.SizeMode       = PictureBoxSizeMode.StretchImage;
        }
예제 #4
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);
            }
        }