private void CustomUploaderUpdateFolder() { using (FolderSelectDialog fsd = new FolderSelectDialog()) { if (fsd.ShowDialog()) { string folderPath = fsd.FileName; string[] files = Directory.GetFiles(folderPath, "*.sxcu", SearchOption.TopDirectoryOnly); int updated = 0; if (files != null) { foreach (string filePath in files) { CustomUploaderItem cui = JsonHelpers.DeserializeFromFile <CustomUploaderItem>(filePath); if (cui != null) { cui.CheckBackwardCompatibility(); CustomUploaderSerialize(cui, folderPath); updated++; } } } MessageBox.Show($"{updated} custom uploader files updated.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
protected override void ImportSlot(FileSystemPath filePath) { // Read the JSON file Dictionary <string, int> lvlTimes = JsonHelpers.DeserializeFromFile <Dictionary <string, int> >(filePath); // TODO: Implement - encode level time back to encrypted format and write to files throw new NotImplementedException(); }
private void CustomUploaderSettingsForm_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) { string[] files = e.Data.GetData(DataFormats.FileDrop, false) as string[]; if (files != null) { foreach (string filePath in files.Where(x => !string.IsNullOrEmpty(x) && x.EndsWith(".sxcu"))) { CustomUploaderItem cui = JsonHelpers.DeserializeFromFile <CustomUploaderItem>(filePath); if (cui != null) { cui.CheckBackwardCompatibility(); CustomUploaderAdd(cui); } } eiCustomUploaders_ImportCompleted(); } } }
public async Task SerializeAsync() { if (IsLoading) { return; } try { IsLoading = true; // Allow the user to select the files FileBrowserResult fileResult = await Services.BrowseUI.BrowseFileAsync(new FileBrowserViewModel() { Title = Resources.Utilities_Serializers_FileSelectionHeader, ExtensionFilter = new FileFilterItem("*.json", "JSON").ToString(), MultiSelection = true, }); if (fileResult.CanceledByUser || !fileResult.SelectedFiles.Any()) { return; } // Allow the user to select the destination directory DirectoryBrowserResult destinationResult = await Services.BrowseUI.BrowseDirectoryAsync(new DirectoryBrowserViewModel() { Title = Resources.Browse_DestinationHeader, }); if (destinationResult.CanceledByUser) { return; } try { await Task.Run(() => { using RCPContext context = new(destinationResult.SelectedDirectory); SelectedType.SelectedMode.InitContext(context); // Serialize every file foreach (FileSystemPath file in fileResult.SelectedFiles) { // Get the destination file FileSystemPath destinationFile = destinationResult.SelectedDirectory + file.Name; // Set the file extension destinationFile = destinationFile.ChangeFileExtension(SelectedType.FileExtension).GetNonExistingFileName(); // Deserialize the file JSON object data = JsonHelpers.DeserializeFromFile(file, SelectedType.Type); // Serialize the data to the destination file SelectedType.Serialize(context, destinationFile.Name, data); } }); await Services.MessageUI.DisplaySuccessfulActionMessageAsync(Resources.Utilities_Serializers_SerializeSuccess); } catch (Exception ex) { Logger.Error(ex, "Serializing files"); await Services.MessageUI.DisplayExceptionMessageAsync(ex, Resources.Utilities_Serializers_SerializeError); } } finally { IsLoading = false; } }