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); }
public static void ShowInformationMessage(Window parentWindow, string Message, string Title) => QModernMessageBox.Info(Message, Title);