private void SaveFile(bool inClosingFile) { try { bool newFile = false; toolStripLabelMain.Text = "正在保存文件..."; if (FileIO.FileInfo.isFileEdited) { if (FileIO.FileInfo.filePath == string.Empty) { newFile = true; string savePath = SelectPath("保存,.."); if (savePath != string.Empty) { FileIO.FileInfo.filePath = savePath; SaveFileByPath(FileIO.FileInfo.filePath, inClosingFile); } else { goto endSave; } } else { SaveFileByPath(FileIO.FileInfo.filePath, inClosingFile); } } //Read file meta data start RAGLINKCommons.RPlatform.SettingsFileIO settingsFileIO = new RAGLINKCommons.RPlatform.SettingsFileIO(); settingsFileIO.SetSettingsFilePath(FileIO.FileInfo.fileConvertedPath); FileIO.FileInfo.fileType = settingsFileIO.GetFileType(); settingsFileIO.Dispose(); //Read file meta data end if (FileIO.FileInfo.fileType != RAGLINKCommons.RPlatform.SettingsContent.FileType.UNKNOW) { this.Text = "RAGLINK 文件编辑器 - " + "[" + FileIO.FileInfo.fileType.ToString() + "]" + Path.GetFileName(FileIO.FileInfo.filePath); FileIO.FileInfo.isFileEdited = false; } else { if (newFile) { FileIO.FileInfo.fileName = string.Empty; FileIO.FileInfo.filePath = string.Empty; } } endSave: toolStripLabelMain.Text = "就绪."; } catch (Exception) { }; }
private bool SaveFileByPath(string filePath, bool inClosingFile) { bool retValue = false; try { if (FileIO.FileInfo.fileConvertedPath == string.Empty) { retValue = false; return(retValue); } textBoxEditor.SaveToFile(FileIO.FileInfo.fileConvertedPath, Encoding.Default); //Read file meta data start RAGLINKCommons.RPlatform.SettingsFileIO settingsFileIO = new RAGLINKCommons.RPlatform.SettingsFileIO(); settingsFileIO.SetSettingsFilePath(FileIO.FileInfo.fileConvertedPath); FileIO.FileInfo.fileType = settingsFileIO.GetFileType(); settingsFileIO.Dispose(); //Read file meta data end //MessageBox.Show(FileIO.FileInfo.fileType.ToString()); if (FileIO.FileInfo.fileType != RAGLINKCommons.RPlatform.SettingsContent.FileType.UNKNOW) { UnlockFile(); if (File.Exists(filePath)) { File.Delete(filePath); } RAGLINKCommons.RPlatform.FileEncryption.DesEncryptFile(FileIO.FileInfo.fileConvertedPath, filePath, RAGLINKCommons.RPlatform.SettingsContent.encryptKey); //MessageBox.Show(FileIO.FileInfo.fileConvertedPath); if (inClosingFile) { File.Delete(FileIO.FileInfo.fileConvertedPath); } this.Text = "RAGLINK 文件编辑器 - " + "[" + FileIO.FileInfo.fileType.ToString() + "]" + Path.GetFileName(FileIO.FileInfo.filePath); } else { MessageBox.Show("保存失败:文件头信息丢失。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { }; if (!inClosingFile) { LockFile(filePath); } return(retValue); }
private bool OpenFile(string filePath) { bool retValue = false; try { inLoading = true; //MessageBox.Show(SettingsContent.tempFilePath); toolStripLabelMain.Text = "正在打开: " + filePath; if (!File.Exists(filePath)) { retValue = false; return(retValue); } string tempFileGUID = RAGLINKCommons.RPlatform.FileEncryption.GUIDGenerate() + ".tmp"; if (!RAGLINKCommons.RPlatform.FileEncryption.DesDecryptFile(filePath, RAGLINKCommons.RPlatform.SettingsContent.tempFilePath + "\\" + tempFileGUID, RAGLINKCommons.RPlatform.SettingsContent.encryptKey)) { retValue = false; return(retValue); } FileIO.FileInfo.filePath = filePath; FileIO.FileInfo.fileName = Path.GetFileName(filePath); FileIO.FileInfo.fileConvertedPath = RAGLINKCommons.RPlatform.SettingsContent.tempFilePath + "\\" + tempFileGUID; //MessageBox.Show(FileIO.FileInfo.fileConvertedPath); //Read file meta data start RAGLINKCommons.RPlatform.SettingsFileIO settingsFileIO = new RAGLINKCommons.RPlatform.SettingsFileIO(); settingsFileIO.SetSettingsFilePath(filePath); FileIO.FileInfo.fileType = settingsFileIO.GetFileType(); settingsFileIO.Dispose(); //Read file meta data end FileIO.FileInfo.isFileOpened = true; FileIO.FileInfo.isFileEdited = false; textBoxEditor.OpenFile(FileIO.FileInfo.fileConvertedPath, Encoding.Default); LockFile(filePath); //MessageBox.Show(FileIO.FileInfo.isFileEdited.ToString()); this.Text = "RAGLINK 文件编辑器 - " + "[" + FileIO.FileInfo.fileType.ToString() + "]" + Path.GetFileName(filePath); toolStripLabelMain.Text = "就绪."; } catch (Exception) { }; inLoading = false; return(retValue); }
static void Main(string[] args) { RAGLINKCommons.RPlatform.SettingsContent.UpdateSettingsPath(); Console.Title = "RAGLINK File Convert"; if (args.Length > 0) { fileNameList.Clear(); fileNameList.AddRange(args); for (int i = 0; i < fileNameList.Count; i++) { Console.Write("Processing: " + fileNameList[i] + "\n"); try { RAGLINKCommons.RPlatform.SettingsFileIO settingsFileIO = new RAGLINKCommons.RPlatform.SettingsFileIO(); settingsFileIO.SetSettingsFilePath(fileNameList[i]); if ((int)settingsFileIO.GetFileType() < (int)RAGLINKCommons.RPlatform.SettingsContent.FileType.UNKNOW && !settingsFileIO.fileEncrypt) { settingsFileIO.WriteValue("file_summary", "encrypt", "1"); string tempFilePath = RAGLINKCommons.RPlatform.SettingsContent.tempFilePath + "\\" + RAGLINKCommons.RPlatform.FileEncryption.GUIDGenerate() + ".tmp"; RAGLINKCommons.RPlatform.FileEncryption.DesEncryptFile(fileNameList[i], tempFilePath, RAGLINKCommons.RPlatform.SettingsContent.encryptKey); File.Delete(fileNameList[i]); File.Copy(tempFilePath, fileNameList[i]); File.Delete(tempFilePath); Console.Write("Done.\n"); } else { Console.Write("Type Error.\n"); } } catch (Exception) { Console.Write("Error.\n"); }; } Console.ReadLine(); } }