예제 #1
0
 private void LoadKethaneDeposits()
 {
     if (PlanetDeposits != null)
     {
         return;
     }
     if (KSP.IO.File.Exists <KethaneController>("Deposits.dat"))
     {
         try
         {
             KSP.IO.BinaryReader Loader = KSP.IO.BinaryReader.CreateForType <KethaneController>("Deposits.dat");
             int    HowManyToLoad       = Loader.ReadInt32();
             byte[] DepositsToLoad      = new byte[HowManyToLoad];
             Loader.Read(DepositsToLoad, 0, HowManyToLoad);
             Loader.Close();
             object ObjectToLoad = KSP.IO.IOUtils.DeserializeFromBinary(DepositsToLoad);
             PlanetDeposits = (Dictionary <string, KethaneDeposits>)ObjectToLoad;
             return;
         }
         catch (Exception e)
         {
             MonoBehaviour.print("Kethane plugin - deposit load error: " + e);
             MonoBehaviour.print("Generating new kethane deposits");
         }
     }
     GenerateKethaneDeposits();
 }
예제 #2
0
파일: Archive.cs 프로젝트: vosechu/KOS
        private void LoadAll()
        {
            Directory.CreateDirectory(ArchiveFolder);

            // Attempt to migrate files from old archive drive
            if (!KSP.IO.File.Exists <File>(HighLogic.fetch.GameSaveFolder + "/arc"))
            {
                return;
            }
            var reader = BinaryReader.CreateForType <File>(HighLogic.fetch.GameSaveFolder + "/arc");

            int fileCount = reader.ReadInt32();

            for (var i = 0; i < fileCount; i++)
            {
                try
                {
                    string filename = reader.ReadString();
                    string body     = reader.ReadString();

                    var file = new File(filename);
                    file.Deserialize(body);

                    Files.Add(file);
                    SaveFile(file);
                }
                catch (EndOfStreamException)
                {
                    break;
                }
            }

            reader.Close();

            KSP.IO.File.Delete <File>(HighLogic.fetch.GameSaveFolder + "/arc");
        }