Exemplo n.º 1
0
        private void SaveHpi(UndoableMapModel map, string filename)
        {
            // flatten before save --- only the base tile is written to disk
            map.ClearSelection();

            var randomValue  = this.rng.Next(1000);
            var tmpExtension = $".mappytemp-{randomValue}";

            var tmpFileName = Path.ChangeExtension(filename, tmpExtension);

            try
            {
                MapSaver.SaveHpi(map, tmpFileName);
                File.Delete(filename);
                File.Move(tmpFileName, filename);
            }
            catch
            {
                // Normally the temp file is deleted by File.Replace.
                // Ensure that it is always deleted if an error occurs.
                File.Delete(tmpFileName);
                throw;
            }

            map.MarkSaved(filename);
        }
Exemplo n.º 2
0
        private static void Save(UndoableMapModel map, string filename)
        {
            // flatten before save --- only the base tile is written to disk
            map.ClearSelection();

            var tntName = filename;
            var otaName = Path.ChangeExtension(filename, ".ota");

            var tmpTntName = tntName + ".mappytemp";
            var tmpOtaName = otaName + ".mappytemp";

            try
            {
                MapSaver.SaveTnt(map, tmpTntName);
                MapSaver.SaveOta(map.Attributes, tmpOtaName);
                File.Delete(tntName);
                File.Delete(otaName);
                File.Move(tmpTntName, tntName);
                File.Move(tmpOtaName, otaName);
            }
            catch
            {
                // Normally the temp files are deleted by File.Replace.
                // Ensure that they are always deleted if an error occurs.
                File.Delete(tmpTntName);
                File.Delete(tmpOtaName);
                throw;
            }

            map.MarkSaved(filename);
        }