public static ConfigAndGestures ImportWgb(string wgbFilePath) { if (!File.Exists(wgbFilePath)) { throw new MigrateException("文件不存在:" + wgbFilePath); } var config = null as PlistConfig; var gestures = null as JsonGestureIntentStore; var cofnigFileName = Path.GetFileName(AppSettings.ConfigFilePath); var gesturesFileName = Path.GetFileName(AppSettings.GesturesFilePath); var arcFile = new StreamingArchiveFile(wgbFilePath); var files = arcFile.FileIndex.IndexedFileNames.ToArray(); var fileShortNames = (from f in files select Path.GetFileName(f)).ToArray(); if (!fileShortNames.Contains(cofnigFileName) || !fileShortNames.Contains(gesturesFileName)) { throw new MigrateException("文件内容不正确(未找到需要的部分): " + wgbFilePath); } try { // iterate the files in the archive: foreach (var fileName in files) { // write the name of the file Debug.Print("File: " + fileName); // extract the file: var file = arcFile.GetFile(fileName); //file.SaveAs("text.txt"); //config file if (Path.GetFileName(fileName) == cofnigFileName) { config = new PlistConfig(file.GetStream(), closeStream: true); } else if (Path.GetFileName(fileName) == gesturesFileName) { gestures = new JsonGestureIntentStore(file.GetStream(), closeStream: true); } } return(new ConfigAndGestures(config, gestures)); } catch (Exception e) { if (e is SystemException) { throw; } throw new MigrateException("导入错误", e); } }
public static void ExportTo(string filePath) { //如果已经存在,则先删掉。否则Archive会添加文件进去 if (File.Exists(filePath)) { File.Delete(filePath); } var arcFile = new StreamingArchiveFile(filePath); arcFile.AddFile(new ArchiveFile(AppSettings.ConfigFilePath)); arcFile.AddFile(new ArchiveFile(AppSettings.GesturesFilePath)); }