Пример #1
0
        private static Result ImportSave(FileSystemClient fs, SaveToImport save)
        {
            SaveDataAttribute key = save.Attribute;

            Result result = fs.CreateSaveData(key.TitleId, key.UserId, key.TitleId, 0, 0, 0);

            if (result.IsFailure())
            {
                return(result);
            }

            bool isOldMounted = false;
            bool isNewMounted = false;

            try
            {
                result = fs.Register("OldSave".ToU8Span(), new LocalFileSystem(save.Path));
                if (result.IsFailure())
                {
                    return(result);
                }

                isOldMounted = true;

                result = fs.MountSaveData("NewSave".ToU8Span(), key.TitleId, key.UserId);
                if (result.IsFailure())
                {
                    return(result);
                }

                isNewMounted = true;

                result = fs.CopyDirectory("OldSave:/", "NewSave:/");
                if (result.IsFailure())
                {
                    return(result);
                }

                result = fs.Commit("NewSave");
            }
            finally
            {
                if (isOldMounted)
                {
                    fs.Unmount("OldSave");
                }

                if (isNewMounted)
                {
                    fs.Unmount("NewSave");
                }
            }

            return(result);
        }