|
@@ -16,7 +16,9 @@ namespace PDF_Master.Model.Dialog.ToolsDialogs
|
|
|
public class CompressDialogModel
|
|
|
{
|
|
|
CPDFDocument tempDocument = null;
|
|
|
- IntPtr compressingIntpr = IntPtr.Zero;
|
|
|
+ private IntPtr compressingIntpr = IntPtr.Zero;
|
|
|
+ //委托函数为全局变量
|
|
|
+ private CPDFDocument.GetPageIndexDelegate indexDelegate = null;
|
|
|
public enum EnumQualityLevel
|
|
|
{
|
|
|
StatusLarge = 100,
|
|
@@ -32,15 +34,23 @@ namespace PDF_Master.Model.Dialog.ToolsDialogs
|
|
|
|
|
|
public void CompressClear()
|
|
|
{
|
|
|
- tempDocument.CompressFile_Cancel(compressingIntpr);
|
|
|
+ if (!compressingIntpr.Equals(IntPtr.Zero))
|
|
|
+ {
|
|
|
+ tempDocument.CompressFile_Cancel(compressingIntpr);
|
|
|
+ }
|
|
|
+
|
|
|
App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
|
|
|
}
|
|
|
private int GetIndex(int pageindex)
|
|
|
{
|
|
|
- App.mainWindowViewModel.Value = (pageindex + 1);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ App.mainWindowViewModel.Value = (pageindex + 1);
|
|
|
|
|
|
- if (App.mainWindowViewModel.Value == App.mainWindowViewModel.MaxValue) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
|
|
|
- return 0;
|
|
|
+ if (App.mainWindowViewModel.Value == App.mainWindowViewModel.MaxValue) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch { Trace.WriteLine("g了嘛"); return -1; }
|
|
|
}
|
|
|
|
|
|
public async void OnOpened(Prism.Services.Dialogs.DialogResult e)
|
|
@@ -51,8 +61,7 @@ namespace PDF_Master.Model.Dialog.ToolsDialogs
|
|
|
{
|
|
|
if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel || e.Result == Prism.Services.Dialogs.ButtonResult.None) { return; }
|
|
|
CPDFDocument doc = null;
|
|
|
- CPDFDocument.GetPageIndexDelegate indexDelegate = null;
|
|
|
-
|
|
|
+ compressingIntpr = IntPtr.Zero;
|
|
|
int compressquality = 45;
|
|
|
doc = e.Parameters.GetValue<CPDFDocument>(ParameterNames.PDFDocument);
|
|
|
filepath = e.Parameters.GetValue<string>(ParameterNames.FilePath);
|
|
@@ -67,7 +76,7 @@ namespace PDF_Master.Model.Dialog.ToolsDialogs
|
|
|
compressquality = e.Parameters.GetValue<int>("compressDialogModel.CompressQuality");
|
|
|
if (doc != null)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
App.mainWindowViewModel.Value = 0;
|
|
|
App.mainWindowViewModel.ProgressTitle = "Compressing";
|
|
|
App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
|
|
@@ -75,19 +84,22 @@ namespace PDF_Master.Model.Dialog.ToolsDialogs
|
|
|
CPDFDocument document = CPDFDocument.InitWithFilePath(doc.FilePath);
|
|
|
document.UnlockWithPassword(password);
|
|
|
indexDelegate += GetIndex;
|
|
|
- compressingIntpr = document.CompressFile_Init(compressquality, indexDelegate);
|
|
|
+ compressingIntpr = document.CompressFile_Init((float)compressquality, indexDelegate);
|
|
|
GC.KeepAlive(indexDelegate);//关键 防止委托过早回收
|
|
|
tempDocument = document;
|
|
|
Trace.WriteLine("compressDialogModel.CompressQuality" + compressquality);
|
|
|
App.mainWindowViewModel.ProcessCloseAction = CompressClear;
|
|
|
- if (await Task.Run<bool>(() => { return document.CompressFile_Start(compressingIntpr, filepath); })) {
|
|
|
- CommonHelper.ShowFileBrowser(filepath);
|
|
|
+ Trace.WriteLine("怎么啦");
|
|
|
+ if (await Task.Run<bool>(() => { return document.CompressFile_Start(compressingIntpr, filepath); }))
|
|
|
+ {
|
|
|
+ CommonHelper.ShowFileBrowser(filepath);
|
|
|
}
|
|
|
-
|
|
|
+ Trace.WriteLine("零零零零怎么");
|
|
|
document.Release();
|
|
|
}
|
|
|
}
|
|
|
- catch {
|
|
|
+ catch
|
|
|
+ {
|
|
|
AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
alertsMessage.ShowDialog("", "Compress file error", App.ServiceLoader.GetString("Text_ok"));
|
|
|
tempDocument.CompressFile_Cancel(compressingIntpr);
|