Beispiel #1
0
        private bool Save()
        {
#if DEBUG
            var stop = new Stopwatch();
            stop.Start();
#endif
            if (_currentId == -1)
            {
                return(true);
            }
            var currentInfo = _applistData[_currentId];
            //todo save
            if (_saveFlag)
            {
                if (!(modeCheck.IsChecked ?? false))
                {
                    if (currentInfo.XmlFile != null)
                    {
                        if (QModernMessageBox.Show("将删除所有自定义效果文件\n继续?", "⚠警告",
                                                   QModernMessageBox.QModernMessageBoxButtons.YesNo, ModernMessageboxIcons.Warning) !=
                            ModernMessageboxResult.Button1)
                        {
                            return(false);
                        }
                        currentInfo.XmlFile = null;
                        File.Delete(currentInfo.XmlFileLocation);
                        //                        if (currentInfo.BakFileExist) {
                        //                            File.Delete(currentInfo.BakFileLocation);
                        //                        }
                        //                        if (Directory.Exists(currentInfo.LogoDirLocation)) {
                        //                            Directory.Delete(currentInfo.LogoDirLocation, true);
                        //                        }

                        _logo = null;
                    }
                }
                else
                {
                    if (currentInfo.XmlFile == null)
                    {
                        currentInfo.XmlFile = new StartmenuXmlFile(currentInfo.XmlFileLocation);
                    }

                    currentInfo.XmlFile.ColorStr      = _currentColorString;
                    currentInfo.XmlFile.TxtForeground = (txtWhiteColor.IsChecked ?? false)
                        ? StartmenuXmlFile.TextCol.light
                        : StartmenuXmlFile.TextCol.dark;
                    currentInfo.XmlFile.ShowTitleOnLargeIcon = largeAppNameCheck.IsChecked ?? false;
                    //保存图片
                    var sha1 = SHA1.Create();
                    // ReSharper disable once AssignNullToNotNullAttribute
                    var pathName = currentInfo.LogoDirLocation;
                    if (!Directory.Exists(pathName))
                    {
                        Directory.CreateDirectory(pathName);
                    }

                    //文件名:[DIR]\__StartmenuIcons__\[SHA1].png
                    if (defineIconCheck.IsChecked ?? false)
                    {
                        if (!string.IsNullOrEmpty(_newLogoLoc))
                        {
                            //计算SHA1
                            var fs   = File.Open(_newLogoLoc, FileMode.Open, FileAccess.Read);
                            var hash = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", string.Empty).ToLower();
                            fs.Close();
                            var fileName           = Path.Combine(pathName, hash) + Path.GetExtension(_newLogoLoc);
                            var fileNameWithoutDir = Path.Combine(Properties.Resources.IconDirName, hash) +
                                                     Path.GetExtension(_newLogoLoc).ToLower();
                            if (!File.Exists(fileName)) //拷贝图像到目录
                            {
                                File.Copy(_newLogoLoc, fileName);
                            }
                            currentInfo.XmlFile.SmallLogoLoc = currentInfo.XmlFile.LargeLogoLoc = fileNameWithoutDir;
                            _newLogoLoc = null;
                        }
                        else if (string.IsNullOrEmpty(currentInfo.XmlFile.SmallLogoLoc))
                        {
                            QModernMessageBox.Info("需要指定作为图标的图片。", "提示");
                            return(false);
                        }
                    }
                    else
                    {
                        currentInfo.XmlFile.LargeLogoLoc = currentInfo.XmlFile.SmallLogoLoc = string.Empty;
                        if (_newLogoLoc == null)
                        {
                            _logo = null;
                        }
                    }

                    try {
                        currentInfo.Backup();
                        currentInfo.XmlFile.Save();
                        undoBtn.IsEnabled = currentInfo.BakFileExist;
                    }
                    catch (UnauthorizedAccessException) {
                        QModernMessageBox.Error("无法保存设定.\n权限不足.", "错误");
                        return(false);
                    }
                    catch (IOException ex) {
                        QModernMessageBox.Error("无法读取该文件设定.\n发生了IO异常,请稍后再试\n更多信息:" + ex.Message, "错误");
                        _sysChangeing         = false;
                        appList.SelectedIndex = -1;
                        return(false);
                    }
                }

                _saveFlag = false;
            }

            //Update file and let the explorer reload the link
            //需要检查是否有连带文件要update的
            //Helper.UpdateFile(currentInfo.FullPath);
            foreach (var item in _applistData)
            {
                if (item.TargetPath == currentInfo.TargetPath)
                {
                    //update
                    Helper.UpdateFile(item.FullPath);
                }
            }

#if DEBUG
            stop.Stop();
            Debug.WriteLine("save takes:" + stop.Elapsed + " ms");
#endif
            return(true);
        }
Beispiel #2
0
        private void ButtonBase_OnClick_7(object sender, RoutedEventArgs e)
        {
            if (_scaleMode && QModernMessageBox.Show("警告,本操作不可逆。\n继续将清除开发者定义的可缩放图标,除非重新安装该程序,否则该图标可能不能恢复。\n继续操作?", "警告",
                                                     QModernMessageBox.QModernMessageBoxButtons.YesNo, ModernMessageboxIcons.Warning) != ModernMessageboxResult.Button1)
            {
                return;
            }


            if (!(_openFile.ShowDialog() ?? false))
            {
                return;
            }
            try {
                var fs  = File.Open(_openFile.FileName, FileMode.Open, FileAccess.Read);
                var img = new Bitmap(fs);
                var win = new ImageSnipWindow(img, new Size(150, 150));
                win.ShowDialog();
                Bitmap tmpBmp;
                switch (win.Result)
                {
                case ImageSnipWindow.SnapWindowResult.Ok:
                    tmpBmp = win.Dst;
                    break;

                case ImageSnipWindow.SnapWindowResult.Cancel:
                    img.Dispose();
                    fs.Close();
                    return;

                case ImageSnipWindow.SnapWindowResult.Ignore:
                    if (img.Size.Width >= 150 && img.Size.Height >= 150)
                    {
                        //尽量使用原图
                        _newLogoLoc = _openFile.FileName;
                        _logo       = img.ToBitmapSource();
                        goto done;
                    }

                    tmpBmp = img;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (tmpBmp.Size.Width < 150 || tmpBmp.Size.Height < 150)
                {
                    if (tmpBmp.Size.Width < 150 && tmpBmp.Size.Height < 150)
                    {
                        var newBmp = new Bitmap(150, 150);
                        var gps    = Graphics.FromImage(newBmp);
                        gps.CompositingQuality = CompositingQuality.HighQuality;
                        gps.Clear(System.Drawing.Color.Transparent);
                        var x = (150 - tmpBmp.Size.Width) / 2;
                        var y = (150 - tmpBmp.Size.Height) / 2;
                        gps.DrawImage(tmpBmp, x, y, tmpBmp.Size.Width, tmpBmp.Size.Height);
                        tmpBmp.Dispose();
                        tmpBmp = newBmp;
                    }
                    else
                    {
                        tmpBmp = new Bitmap(tmpBmp, 150, 150);
                    }
                }

                _logo       = tmpBmp.ToBitmapSource();
                _newLogoLoc = Path.GetTempFileName() + ".png";
                tmpBmp.Save(_newLogoLoc, ImageFormat.Png);
                tmpBmp.Dispose();
done:
                img.Dispose();
                fs.Close();
            }
            catch (IOException ex) {
                QModernMessageBox.Error($"图片载入失败\n未知错误,无法读取此文件\n详细信息:{ex.Message}", "错误");
                return;
            }

            _saveFlag = true;
            UpdateRender();
        }
Beispiel #3
0
 public static void ShowErrorMessage(Window parentWindow, Exception Ex) => QModernMessageBox.Error(parentWindow, Ex.Message, "错误");
Beispiel #4
0
 /// <summary>
 /// 错误消息框
 /// </summary>
 /// <param name="Ex"></param>
 public static void ShowErrorMessage(Exception Ex) => QModernMessageBox.Error(Ex.Message, "错误");
Beispiel #5
0
 public static void ShowErrorMessage(Window parentWindow, string Message) => QModernMessageBox.Error(parentWindow, Message, "错误");
Beispiel #6
0
 /// <summary>
 /// 错误消息框
 /// </summary>
 /// <param name="Message"></param>
 public static void ShowErrorMessage(string Message) => QModernMessageBox.Error(Message, "错误");