예제 #1
0
        /// <summary>
        /// Exports the save slot from the specified path
        /// </summary>
        /// <param name="outputFilePath">The output file path</param>
        /// <returns>The task</returns>
        protected override Task ExportSaveDataAsync(FileSystemPath outputFilePath)
        {
            // Get the serialized data
            var data = BinarySerializableHelpers.ReadFromFile <RaymanMPCSaveData>(SaveSlotFilePath, OpenSpaceSettings.GetDefaultSettings(OpenSpaceGame.RaymanM, Platform.PC), RCPServices.App.GetBinarySerializerLogger());

            // Export the data
            JsonHelpers.SerializeToFile(data, outputFilePath);

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Exports the save slot from the specified path
        /// </summary>
        /// <param name="outputFilePath">The output file path</param>
        /// <returns>The task</returns>
        protected override Task ExportSaveDataAsync(FileSystemPath outputFilePath)
        {
            // Get the serialized level data
            var data = BinarySerializableHelpers.ReadFromFile <JungleRunPCSaveData>(SaveSlotFilePath, UbiArtSettings.GetSaveSettings(UbiArtGame.RaymanJungleRun, Platform.PC), RCPServices.App.GetBinarySerializerLogger()).Levels;

            // Export the data
            JsonHelpers.SerializeToFile(data, outputFilePath);

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Exports a localization file to a JSON file
        /// </summary>
        /// <returns>The task</returns>
        public async Task ExportToJSONAsync()
        {
            // Get the input file
            var inputResult = await Services.BrowseUI.BrowseFileAsync(new FileBrowserViewModel()
            {
                Title            = Resources.UbiArtU_LocalizationConverterExportSelectionHeader,
                DefaultDirectory = DefaultLocalizationDirectory ?? FileSystemPath.EmptyPath,
                ExtensionFilter  = new FileFilterItem($"*{LocalizationFileExtension}", Resources.UbiArtU_LocalizationConverterLocFilterDescription).StringRepresentation,
                DefaultName      = $"localisation{LocalizationFileExtension}"
            });

            if (inputResult.CanceledByUser)
            {
                return;
            }

            // Get the output file
            var outputResult = await Services.BrowseUI.SaveFileAsync(new SaveFileViewModel()
            {
                Title       = Resources.ExportDestinationSelectionHeader,
                DefaultName = inputResult.SelectedFile.ChangeFileExtension(new FileExtension(".json")).Name,
                Extensions  = new FileFilterItem("*.json", Resources.FileFilterDescription_JSON).StringRepresentation
            });

            if (outputResult.CanceledByUser)
            {
                return;
            }

            try
            {
                // Serialize the data into the new file
                JsonHelpers.SerializeToFile(Deserialize(inputResult.SelectedFile), outputResult.SelectedFileLocation);

                await Services.MessageUI.DisplaySuccessfulActionMessageAsync(Resources.UbiArtU_LocalizationConverterExportSuccess);
            }
            catch (Exception ex)
            {
                ex.HandleError("Exporting localization file to JSON");
                await Services.MessageUI.DisplayExceptionMessageAsync(ex, Resources.UbiArtU_LocalizationConverterExportError);
            }
        }
        /// <summary>
        /// Exports the save slot from the specified path
        /// </summary>
        /// <param name="outputFilePath">The output file path</param>
        /// <returns>The task</returns>
        protected override Task ExportSaveDataAsync(FileSystemPath outputFilePath)
        {
            // Create streams
            using var saveFileStream    = File.OpenRead(SaveSlotFilePath);
            using var decodedDataStream = new MemoryStream();

            // Decode the save file
            new Rayman12PCSaveDataEncoder().Decode(saveFileStream, decodedDataStream);

            // Set position to 0
            decodedDataStream.Position = 0;

            // Get the serialized data
            var data = BinarySerializableHelpers.ReadFromStream <Rayman1PCSaveData>(decodedDataStream, Ray1Settings.GetDefaultSettings(Ray1Game.Rayman1, Platform.PC), RCPServices.App.GetBinarySerializerLogger());

            // Export the data
            JsonHelpers.SerializeToFile(data, outputFilePath);

            return(Task.CompletedTask);
        }
예제 #5
0
        /// <summary>
        /// Saves all user data for the application
        /// </summary>
        public virtual async Task SaveUserDataAsync()
        {
            // Lock the saving of user data
            using (await SaveUserDataAsyncLock.LockAsync())
            {
                // Run it as a new task
                await Task.Run(() =>
                {
                    // Save the user data
                    try
                    {
                        // Save the user data
                        JsonHelpers.SerializeToFile(RCPServices.Data, CommonPaths.AppUserDataPath);

                        RL.Logger?.LogInformationSource($"The application user data was saved");
                    }
                    catch (Exception ex)
                    {
                        ex.HandleCritical("Saving user data");
                    }
                });
            }
        }
 /// <summary>
 /// Serializes data as JSON to a file
 /// </summary>
 /// <typeparam name="T">The type of data</typeparam>
 /// <param name="data">The data to serialize</param>
 /// <param name="filePath">The file path to save to</param>
 protected void SerializeJSON <T>(T data, FileSystemPath filePath)
 {
     // Serialize the data
     JsonHelpers.SerializeToFile(data, filePath);
 }