Added Import function

This commit is contained in:
Jaex 2016-02-10 21:55:57 +02:00
parent ec0da15666
commit 6b6f3fdb7c
3 changed files with 40 additions and 19 deletions

View file

@ -1207,7 +1207,7 @@ public static string SaveImageFileDialog(Image img, string filePath = "")
sfd.FileName = Path.GetFileNameWithoutExtension(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"; 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) if (sfd.ShowDialog() == DialogResult.OK)

View file

@ -40,13 +40,17 @@ public static bool Export()
{ {
try 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 else
{ {
@ -58,7 +62,7 @@ public static bool Export()
SevenZipCompressor zip = new SevenZipCompressor(); SevenZipCompressor zip = new SevenZipCompressor();
zip.ArchiveFormat = OutArchiveFormat.SevenZip; zip.ArchiveFormat = OutArchiveFormat.SevenZip;
zip.CompressionLevel = CompressionLevel.Ultra; zip.CompressionLevel = CompressionLevel.Normal;
zip.CompressionMethod = CompressionMethod.Lzma2; zip.CompressionMethod = CompressionMethod.Lzma2;
Dictionary<string, string> files = new Dictionary<string, string>(); Dictionary<string, string> files = new Dictionary<string, string>();
@ -83,8 +87,6 @@ public static bool Export()
} }
} }
string exportPath = Path.Combine(exportFolder, "ShareX_backup.sxb");
zip.CompressFileDictionary(files, exportPath); zip.CompressFileDictionary(files, exportPath);
return true; return true;
@ -99,6 +101,8 @@ public static bool Export()
} }
private static void AddFileToDictionary(Dictionary<string, string> files, string filePath, string subFolder = null) private static void AddFileToDictionary(Dictionary<string, string> files, string filePath, string subFolder = null)
{
if (File.Exists(filePath))
{ {
string destinationPath = Path.GetFileName(filePath); string destinationPath = Path.GetFileName(filePath);
@ -109,18 +113,34 @@ private static void AddFileToDictionary(Dictionary<string, string> files, string
files.Add(destinationPath, filePath); files.Add(destinationPath, filePath);
} }
}
public static bool Import(string filePath) public static bool Import()
{ {
try 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(); Set7ZipLibraryPath();
Helpers.CreateDirectoryIfNotExist(filePath); using (SevenZipExtractor zip = new SevenZipExtractor(importPath))
using (SevenZipExtractor zip = new SevenZipExtractor(filePath))
{ {
// TODO zip.ExtractArchive(Program.PersonalFolder);
return true; return true;
} }
} }

View file

@ -428,6 +428,7 @@ private void btnExport_Click(object sender, EventArgs e)
private void btnImport_Click(object sender, EventArgs e) private void btnImport_Click(object sender, EventArgs e)
{ {
ExportImportManager.Import();
} }
#endregion Export / Import #endregion Export / Import