diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index b4542efe0..98fbd4ee3 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -1207,7 +1207,7 @@ public static string SaveImageFileDialog(Image img, string filePath = "") sfd.FileName = Path.GetFileNameWithoutExtension(filePath); } - sfd.DefaultExt = ".png"; + sfd.DefaultExt = "png"; sfd.Filter = "PNG (*.png)|*.png|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (*.tif, *.tiff)|*.tif;*.tiff"; if (sfd.ShowDialog() == DialogResult.OK) diff --git a/ShareX/ExportImportManager.cs b/ShareX/ExportImportManager.cs index 8fe0ebd49..ce6734d7b 100644 --- a/ShareX/ExportImportManager.cs +++ b/ShareX/ExportImportManager.cs @@ -40,13 +40,17 @@ public static bool Export() { try { - string exportFolder; + string exportPath; - using (FolderSelectDialog dlg = new FolderSelectDialog()) + using (SaveFileDialog sfd = new SaveFileDialog()) { - if (dlg.ShowDialog()) + sfd.DefaultExt = "sxb"; + sfd.FileName = "ShareX_backup.sxb"; + sfd.Filter = "ShareX backup (*.sxb)|*.sxb|All files (*.*)|*.*"; + + if (sfd.ShowDialog() == DialogResult.OK) { - exportFolder = dlg.FileName; + exportPath = sfd.FileName; } else { @@ -58,7 +62,7 @@ public static bool Export() SevenZipCompressor zip = new SevenZipCompressor(); zip.ArchiveFormat = OutArchiveFormat.SevenZip; - zip.CompressionLevel = CompressionLevel.Ultra; + zip.CompressionLevel = CompressionLevel.Normal; zip.CompressionMethod = CompressionMethod.Lzma2; Dictionary files = new Dictionary(); @@ -83,8 +87,6 @@ public static bool Export() } } - string exportPath = Path.Combine(exportFolder, "ShareX_backup.sxb"); - zip.CompressFileDictionary(files, exportPath); return true; @@ -100,27 +102,45 @@ public static bool Export() private static void AddFileToDictionary(Dictionary files, string filePath, string subFolder = null) { - string destinationPath = Path.GetFileName(filePath); - - if (!string.IsNullOrEmpty(subFolder)) + if (File.Exists(filePath)) { - destinationPath = Path.Combine(subFolder, destinationPath); - } + string destinationPath = Path.GetFileName(filePath); - files.Add(destinationPath, filePath); + if (!string.IsNullOrEmpty(subFolder)) + { + destinationPath = Path.Combine(subFolder, destinationPath); + } + + files.Add(destinationPath, filePath); + } } - public static bool Import(string filePath) + public static bool Import() { try { + string importPath; + + using (OpenFileDialog ofd = new OpenFileDialog()) + { + ofd.Filter = "ShareX backup (*.sxb)|*.sxb|All files (*.*)|*.*"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + importPath = ofd.FileName; + } + else + { + return false; + } + } + Set7ZipLibraryPath(); - Helpers.CreateDirectoryIfNotExist(filePath); - - using (SevenZipExtractor zip = new SevenZipExtractor(filePath)) + using (SevenZipExtractor zip = new SevenZipExtractor(importPath)) { - // TODO + zip.ExtractArchive(Program.PersonalFolder); + return true; } } diff --git a/ShareX/Forms/ApplicationSettingsForm.cs b/ShareX/Forms/ApplicationSettingsForm.cs index 0e2825f04..192d07312 100644 --- a/ShareX/Forms/ApplicationSettingsForm.cs +++ b/ShareX/Forms/ApplicationSettingsForm.cs @@ -428,6 +428,7 @@ private void btnExport_Click(object sender, EventArgs e) private void btnImport_Click(object sender, EventArgs e) { + ExportImportManager.Import(); } #endregion Export / Import