Пример #1
0
 /// <summary>
 /// 解压存档到游戏存档目录
 /// </summary>
 /// <param name="file"></param>
 public static void Unzip(string file)
 {
     Directory.GetFiles(SaveManager.SavePath, "*.tw*", SearchOption.TopDirectoryOnly)
     .Do(File.Delete);
     if (File.Exists(Path.Combine(SaveManager.SavePath, "date.json")))
     {
         File.Delete(Path.Combine(SaveManager.SavePath, "date.json"));
     }
     SevenZipHelper.Extract(file, SaveManager.SavePath, true);
 }
Пример #2
0
        /// <summary>
        /// 存档为压缩包
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static SaveData ParseZip(string path)
        {
            SaveData data  = null;
            var      items = SevenZipHelper.List(path).ToList();

            if (items.Any(t => t.path == "date.json"))
            {
                using (var tmp = new TempDir())
                {
                    SevenZipHelper.Extract(path, tmp.Dir, include: "date.json");
                    var json = File.ReadAllText(Path.Combine(tmp.Dir, "date.json"), Encoding.UTF8);
                    data = JsonConvert.DeserializeObject(json, typeof(SaveData)) as SaveData;
                }
            }
            else if (!items.Any(t => t.path == "TW_Save_Date_0.twV0") &&
                     !items.Any(t => t.path == "TW_Save_Date_0.tw"))
            {
                throw new InvalidDataException(path); // 错误存档
            }
            else // 不含加速文件
            {
                bool   rijndeal = true;
                string files    = null;
                if (items.Any(t => t.path == "TW_Save_Date_0.twV0"))
                {
                    rijndeal = false;
                    files    = "TW_Save_Date_0.twV0";
                }
                else if (items.Any(t => t.path == "TW_Save_Date_0.tw"))
                {
                    rijndeal = true;
                    files    = "TW_Save_Date_0.tw";
                }
                if (files != null)
                {
                    using (var tmp = new TempDir())
                    {
                        SevenZipHelper.Extract(path, tmp.Dir, include: files);
                        DateFile.SaveDate date = ReadSaveDate(Path.Combine(tmp.Dir, files), rijndeal);
                        data = new SaveData(date._mainActorName, date._year, date._samsara,
                                            date._dayTrun, date._playerSeatName, date._playTime);
                        var dataPath = Path.Combine(tmp.Dir, "date.json");
                        File.WriteAllText(dataPath, JsonConvert.SerializeObject(data));
                        SevenZipHelper.Update(path, dataPath);
                    }
                }
            }
            return(data);
        }