// 打开文件 private void OpenFile(string openFilename) { string text = _statusLabel.Text; try { _fileToolStripMenuItem.Enabled = false; _optionsToolStripMenuItem.Enabled = false; _statusLabel.Text = $"Loading {openFilename}"; LogFileWriter logFileWriter = null; if (_writeLogFileToolStripMenuItem.Checked) { logFileWriter = new LogFileWriter(openFilename + ".xml"); } EditedFile = EsfCodecUtil.LoadEsfFile(openFilename); FileName = openFilename; logFileWriter?.Close(); // 自定义检索 try { Tw3kSearch.SearchFaction(EditedFile); } catch (Exception e) { Debug.WriteLine(e); throw; } // 自定义换词条 // ChangePersonality(EditedFile, 101, CeoCategory.Personality, // "3k_main_ceo_trait_personality_kind", "3k_main_ceo_trait_personality_humble", // "3k_main_ceo_trait_personality_fraternal"); Text = $"{Path.GetFileName(openFilename)} - EditSF {Application.ProductVersion}"; foreach (ToolStripItem dropDownItem in _bookmarksToolStripMenuItem.DropDownItems) { if (dropDownItem is BookmarkItem) { dropDownItem.Enabled = true; } } } catch (Exception value) { _statusLabel.Text = text; Console.WriteLine(value); } finally { _fileToolStripMenuItem.Enabled = true; _optionsToolStripMenuItem.Enabled = true; } }
private void OpenFile(string openFilename) { string oldStatus = statusLabel.Text; try { fileToolStripMenuItem.Enabled = false; optionsToolStripMenuItem.Enabled = false; // EsfCodec codec = EsfCodecUtil.GetCodec(stream); // updater.StartLoading(openFilename, codec); statusLabel.Text = string.Format("Loading {0}", openFilename); LogFileWriter logger = null; if (writeLogFileToolStripMenuItem.Checked) { logger = new LogFileWriter(openFilename + ".xml"); //codec.NodeReadFinished += logger.WriteEntry; //codec.Log += logger.WriteLogEntry; } EditedFile = EsfCodecUtil.LoadEsfFile(openFilename); //updater.LoadingFinished(); FileName = openFilename; if (logger != null) { logger.Close(); //codec.NodeReadFinished -= logger.WriteEntry; //codec.Log -= logger.WriteLogEntry; } Text = string.Format("{0} - EditSF {1}", Path.GetFileName(openFilename), Application.ProductVersion); foreach (ToolStripItem item in bookmarksToolStripMenuItem.DropDownItems) { if (item is BookmarkItem) { item.Enabled = true; } } } catch (Exception exception) { statusLabel.Text = oldStatus; Console.WriteLine(exception); } finally { fileToolStripMenuItem.Enabled = true; optionsToolStripMenuItem.Enabled = true; } }