示例#1
0
        public static void SaveTheGame()
        {
            // Make sure there isn't already a temp directory
            if (Directory.Exists($"{base_dir}/{temp_dir}"))
            {
                Directory.Delete($"{base_dir}/{temp_dir}", true);
            }

            // Crete a temp directory to store the save data in, so that if the saving fails data isn't corrupted
            Directory.CreateDirectory($"{base_dir}/{temp_dir}");

            // Save everything as JSON objects inside .json files, and store them in the temp directory
            JSONSerializer.SerializeEverything();

            // Delete the existing save file
            if (Directory.Exists($"{base_dir}/{adventure_name}"))
            {
                Directory.Delete($"{base_dir}/{adventure_name}", true);
            }

            // Create the save file folder
            Directory.CreateDirectory($"{base_dir}/{adventure_name}");

            // Move all the files from the temp directory to the save file folder
            DirectoryInfo temp_directory = new DirectoryInfo($"{base_dir}/{temp_dir}");

            foreach (FileInfo file in temp_directory.GetFiles("*.json"))
            {
                File.Move($"{base_dir}/{temp_dir}/{file.Name}", $"{base_dir}/{adventure_name}/{file.Name}");
            }

            Directory.Delete($"{base_dir}/{temp_dir}", true);

            // Create a file with a disclaimer that warns against manually editing save files
            File.WriteAllText($"{base_dir}/README.txt", @"-IMPORTANT NOTE-
Editing these .json files is a VERY easy way to corrupt your save file.
Unless you are familiar with the inner-workings of the game and know
how to read/edit .json files, it's highly recommended that you turn away.");
        }
示例#2
0
        public async Task <T> Save <T>(T document) where T : Document
        {
            var list = await GetAll <T>();

            var exists = list.FirstOrDefault(x => x.Id == document.Id);

            if (exists != null)
            {
                exists = document;
            }
            else
            {
                if (list.Count == 0)
                {
                    document.Id = 1;
                }
                else
                {
                    document.Id = list.Max(x => x.Id) + 1;
                }
                list.Add(document);
            }

            var serializer = new JSONSerializer <List <T> >();

            using (var json = serializer.SerializeAsStream(list))
            {
                using (var stream = await _streamer.StreamForWriteAsync(GetFileNameFromType(typeof(T))))
                {
                    await json.CopyToAsync(stream);

                    await stream.FlushAsync();
                }
            }
            return(document);
        }
示例#3
0
 public void StartLogger()
 {
     serializer = new JSONSerializer();
     serializer.StartLogFile(Environs.FileSystem.Paths["transferCavityData"] + "log.json");
     serializer.StartProcessingData();
 }
示例#4
0
 public void StartLoggingCurrent()
 {
     serializer = new JSONSerializer();
     serializer.StartLogFile((String)Environs.FileSystem.Paths["scanMasterDataPath"] +
         Environs.FileSystem.GenerateNextDataFileName() + ".json");
     serializer.StartProcessingData();
 }