Exemple #1
0
        public Save(string filePath)
        {
            if (File.Exists(filePath))
            {
                if (_saveFile != null)
                {
                    _saveReader.Close();
                    _saveFile.Close();
                }
                try { _saveFile = new FileStream(filePath, FileMode.Open); } catch { SuccessfullyLoaded = false; }
                if (_saveFile == null || !SuccessfullyLoaded || !_saveFile.CanWrite)
                {
                    MessageBox.Show(
                        $"Error: File {Path.GetFileName(filePath)} is being used by another process. Please close any process using it before editing!",
                        "File Opening Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    try
                    {
                        _saveFile?.Close();
                    }
                    catch
                    {
                        // ignored
                    }
                    return;
                }

                _saveReader = new BinaryReader(_saveFile);

                if (_saveFile.Length == 0x20000)
                {
                    var data = _saveReader.ReadBytes(0x20000);
                    if (Encoding.ASCII.GetString(data, 4, 4) == "JFAN") // Check for DnM which is byteswapped
                    {
                        OriginalSaveData = SaveDataManager.ByteSwap(data);
                        SaveType         = SaveType.DoubutsuNoMori;
                    }
                    else
                    {
                        OriginalSaveData = data;
                        SaveType         = SaveType.AnimalForest;
                    }
                }
                else
                {
                    OriginalSaveData = _saveReader.ReadBytes((int)_saveFile.Length);
                }


                WorkingSaveData = new byte[OriginalSaveData.Length];
                Buffer.BlockCopy(OriginalSaveData, 0, WorkingSaveData, 0, OriginalSaveData.Length);

                SaveType            = SaveDataManager.GetSaveType(OriginalSaveData) ?? SaveType;
                SaveGeneration      = SaveDataManager.GetSaveGeneration(SaveType);
                FullSavePath        = filePath;
                SaveName            = Path.GetFileNameWithoutExtension(filePath);
                SavePath            = Path.GetDirectoryName(filePath) + Path.DirectorySeparatorChar;
                SaveExtension       = Path.GetExtension(filePath);
                SaveId              = SaveDataManager.GetGameId(SaveType);
                SaveDataStartOffset = SaveDataManager.GetSaveDataOffset(SaveId.ToLower(), SaveExtension.Replace(".", "").ToLower());
                SaveInfo            = SaveDataManager.GetSaveInfo(SaveType);

                if (SaveType == SaveType.WildWorld || SaveGeneration == SaveGeneration.N3DS)
                {
                    IsBigEndian = false;
                }

                _saveReader.Close();
                _saveFile.Close();
                _saveReader.Dispose();
                _saveFile.Dispose();

                // Create a Backup
                if (Properties.Settings.Default.BackupFiles)
                {
                    _backup = new Backup(this);
                }
            }
            else
            {
                MessageBox.Show("File doesn't exist!");
            }
        }
Exemple #2
0
        public Save(string filePath)
        {
            if (File.Exists(filePath))
            {
                if (_saveFile != null)
                {
                    _saveReader.Close();
                    _saveFile.Close();
                }
                try { _saveFile = new FileStream(filePath, FileMode.Open); } catch { SuccessfullyLoaded = false; }
                if (_saveFile == null || !SuccessfullyLoaded || !_saveFile.CanWrite)
                {
                    MessageBox.Show(
                        $"Error: File {Path.GetFileName(filePath)} is being used by another process. Please close any process using it before editing!",
                        "File Opening Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    try
                    {
                        _saveFile?.Close();
                    }
                    catch
                    {
                        // ignored
                    }
                    return;
                }

                _saveReader = new BinaryReader(_saveFile);
                SaveData    = _saveReader.ReadBytes((int)_saveFile.Length);
                _byteswap   = this.IsByteSwapped();
                if (_byteswap)
                {
                    SaveData = SaveDataManager.ByteSwap(SaveData); // Only byteswap the working data.
                }

                SaveType            = this.GetSaveType();
                SaveGeneration      = SaveDataManager.GetSaveGeneration(SaveType);
                FullSavePath        = filePath;
                SaveName            = Path.GetFileNameWithoutExtension(filePath);
                SavePath            = Path.GetDirectoryName(filePath) + Path.DirectorySeparatorChar;
                SaveExtension       = Path.GetExtension(filePath);
                SaveId              = SaveDataManager.GetGameId(SaveType);
                SaveDataStartOffset = SaveDataManager.GetSaveDataOffset(SaveId.ToLower(), SaveExtension?.Replace(".", "").ToLower());
                SaveInfo            = SaveDataManager.GetSaveInfo(SaveType);

                if (SaveType == SaveType.WildWorld || SaveGeneration == SaveGeneration.N3DS)
                {
                    IsBigEndian = false;
                }

                _saveReader.Close();
                _saveFile.Close();
                _saveReader.Dispose();
                _saveFile.Dispose();

                // Create a Backup
                if (Properties.Settings.Default.BackupFiles)
                {
                    _backup = new Backup(this);
                }
            }
            else
            {
                MessageBox.Show("File doesn't exist!");
            }
        }