mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added Import function
This commit is contained in:
parent
ec0da15666
commit
6b6f3fdb7c
3 changed files with 40 additions and 19 deletions
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -100,27 +102,45 @@ 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)
|
||||||
{
|
{
|
||||||
string destinationPath = Path.GetFileName(filePath);
|
if (File.Exists(filePath))
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(subFolder))
|
|
||||||
{
|
{
|
||||||
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
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue