Преглед на файлове

Merge branch 'develop_PDFReaderProNew' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderProNew

tangchao преди 1 година
родител
ревизия
e89260dbcc

+ 0 - 24
PDF Office/PDF Master/Class/AIInfo/KMAIRequestServerManager.swift

@@ -370,14 +370,7 @@ class ResultWrapper: NSObject {
         var semaphore = DispatchSemaphore (value: 0)
         
         var escapedString = q
-        if q.contains("\n") || q.contains("\r") {
-            escapedString = q.replacingOccurrences(of: "\n", with: "\\n")
-            escapedString = escapedString.replacingOccurrences(of: "\r", with: "\\r")
-        } else if q.contains("\u{2028}") {
-            
-        }
         escapedString = String(data: escapedString.data(using: .utf8)!, encoding: .utf8)!
-//        let escapedString = String(data: q.data(using: .utf8)!, encoding: .utf8)!
         let paraDict = ["text":escapedString,
                         "from":from,
                         "to":to,
@@ -405,30 +398,13 @@ class ResultWrapper: NSObject {
                 let code: String = jsonObject!["code"] as? String ?? "06005"
                 let message: String = jsonObject!["message"] as? String ?? "unknown error"
                 let error = NSError(domain: message, code: Int(code)!)
-//                let result = ResultWrapper(success: true, result: data1, message: message, code: Int(code)!, error: error, state: .textTranslate)
-//                if result.code == 200 {
-//                    result.success = true
-//                    complete(result)
-//                } else {
-//                    result.success = false
-//                    complete(result)
-//                }
                 if Int(code)! == 200 {
                     var resultStr = data1["dst"] as! String
-                    if resultStr.contains("\\n") || resultStr.contains("\\r") {
-                        resultStr = resultStr.replacingOccurrences(of: "\\n", with: "\n")
-                        resultStr = resultStr.replacingOccurrences(of: "\\r", with: "\r")
-                    } else if q.contains("\u{2028}") {
-                        
-                    }
                     complete(ResultWrapper(success: true, content: resultStr))
                 } else {
                     complete(ResultWrapper(success: false, content: message))
                 }
             } else {
-//                let error = NSError(domain: "unknown error", code: 404)
-//                let result = ResultWrapper(success: false, result: [:], message: "unknown error", code: 404, error: error, state: .textTranslate)
-//                complete(result)
                 complete(ResultWrapper(success: false, content: "unknown error"))
             }
            semaphore.signal()

+ 2 - 2
PDF Office/PDF Master/Class/Batch/Data/KMBatchOperateFile.swift

@@ -14,8 +14,8 @@ import Cocoa
     var outputFilePath: String = ""
     lazy var sizeString: String = {
         let attributes = try? FileManager.default.attributesOfItem(atPath: self.filePath)
-        let fileSize = attributes?[FileAttributeKey.size] as? Float ?? 0
-        let _sizeString = self.fileSizeString(fSize: fileSize)
+        let fileSize: Int = attributes?[FileAttributeKey.size] as! Int
+        let _sizeString = self.fileSizeString(fSize: Float(fileSize))
         return _sizeString
     }()
     var fileType: KMBatchOperateFileType?

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/Convert/NewController/Common/KMPDFConvert.swift

@@ -274,11 +274,11 @@ class KMPDFConvert: Operation {
             return
         }
         
-        if self.convertType == .csv && isExtractTable{
+        if self.convertType == .csv /*&& isExtractTable*/{
             self.converter = CPDFConverterCsv.init(url: URL(fileURLWithPath: filePath), password: self.password)
             self.converter.delegate = self
             let options = CPDFConvertCsvOptions()
- 
+            options.isAILayoutAnalysis = isExtractTable
             self.converter.convert(toFilePath: self.outputFilePath, pageIndexs: self.pages, options: options)
             return
         }

+ 3 - 0
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMVerificationActivateViewController.h

@@ -6,11 +6,14 @@
 //
 
 #import <Cocoa/Cocoa.h>
+#import "KMVerificationWindowController.h"
 
 @interface KMVerificationActivateViewController : NSViewController
 
 @property (nonatomic,copy) void (^callback) (NSInteger index, NSString *string);
 
+@property (nonatomic, assign) KMVerificationType type;
+
 - (void)setEnabled:(BOOL)enabled;
 
 @end

+ 1 - 0
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMVerificationActivateViewController.m

@@ -95,6 +95,7 @@
     [self.sublabel setTextColor:[KMAppearance KM_242424_Color75]];
     [self.textLabel setTextColor:[KMAppearance KMColor_Layout_H0]];
     
+    self.type = KMVerificationTypeActivate;
 }
 
 - (void)viewDidAppear {

+ 147 - 6
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMVerificationWindowController.m

@@ -150,15 +150,15 @@ static KMVerificationWindowController *_currentWindowController = nil;
         _normalViewController = [[KMVerificationViewController alloc] init];
         _normalViewController.callback = ^(NSInteger index) {
             if (index == 0) {
-                [blockSelf setContentView:blockSelf.activateViewController.view];
+                [self setContentView:self.activateViewController.view];
             } else if (index == 1) {
                 if (KMVerificationTypeActivateExpired == self.type) {
-                    [blockSelf verificationFeedback];
+                    [self verificationFeedback];
                 } else {
-                    [blockSelf close];
+                    [self close];
                 }
             } else {
-                [blockSelf verificationBuy];
+                [self verificationBuy];
             }
         };
         if (KMVerificationTypeTrialExpired == self.type) {
@@ -192,9 +192,16 @@ static KMVerificationWindowController *_currentWindowController = nil;
                     }
                 }
             } else {
-                [blockSelf verificationActivate:string];
+                if (blockSelf.type == KMVerificationTypeActivateAIInfo) {
+                    [blockSelf verificationActivateAIInfo:string];
+                } else {
+                    [blockSelf verificationActivate:string];
+                }
             }
         };
+        if (self.type == KMVerificationTypeActivateAIInfo) {
+            _activateViewController.type = self.type;
+        }
     }
     return _activateViewController;
 }
@@ -382,6 +389,9 @@ static KMVerificationWindowController *_currentWindowController = nil;
     } else if (self.type == KMVerificationTypeTrialSuccess ||
                self.type == KMVerificationTypeRepeatTrialSuccess) {
         [self setContentView:self.trialSuccessController.view];
+    } else if (KMVerificationTypeActivateAIInfo == self.type) {
+        [self setContentView:self.activateViewController.view];
+        self.activateViewController.type = self.type;
     }
 }
 
@@ -473,10 +483,141 @@ static KMVerificationWindowController *_currentWindowController = nil;
     }];
 }
 
+- (void)verificationActivateAIInfo:(NSString *)license {
+    if (license.length <= 0) {
+        return;
+    }
+    if (![self isConnectionAvailable]) {
+        NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
+                                         defaultButton:NSLocalizedString(@"OK", nil)
+                                       alternateButton:nil
+                                           otherButton:nil
+                             informativeTextWithFormat:@"", nil];
+        
+        NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
+        accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
+        accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
+        accessryBtn.bordered = NO;
+        accessryBtn.target = self;
+        accessryBtn.action = @selector(accessryBtnClicked:);
+        NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
+        [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
+        [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
+        [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
+        
+        accessryBtn.attributedTitle = mutAttrString;
+        
+        NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
+        CGRect frame = accessryBtn.frame;
+        frame.size.height = rect.size.height;
+        accessryBtn.frame = frame;
+        alert.accessoryView = accessryBtn;
+        
+        [alert runModal];
+        return;
+    }
+    __block __typeof(self) blockSelf = self;
+    self.progressIndicator.hidden = NO;
+    [self.progressIndicator startAnimation:nil];
+    [self.activateViewController setEnabled:NO];
+    NSDictionary *infoDic = @{@"cdkey":license};
+    [[AIInfoManager defaultManager] activateAIWithInfo:infoDic complention:^(NSDictionary *info, NSError *error) {
+        blockSelf.progressIndicator.hidden = YES;
+        [blockSelf.progressIndicator stopAnimation:nil];
+        [blockSelf.activateViewController setEnabled:YES];
+        if (error) {
+
+            NSString *tTitle0 = NSLocalizedString(@"The license you have entered is not correct. Please enter valid license.", nil);
+            NSString *tTitle1 = NSLocalizedString(@"Please confirm your PDF Reader Pro AI license code through the email you provided when purchasing.", nil);
+
+            NSString *message = [NSString stringWithFormat:@"%@\n\n%@", tTitle0, tTitle1];
+
+            if (ActivityErrorTypeCDKeyEmpty == error.code) {
+                message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number can not be empty.", nil), @""];
+            } else if (ActivityErrorTypeCDKeyNotExist == error.code) {
+                message = [NSString stringWithFormat:@"%@\n\n%@", NSLocalizedString(@"License number does not exist.", nil), @""];
+            } else if (ActivityErrorTypeOutNumber == error.code) {
+                NSString *tMsg0 = NSLocalizedString(@"The devices connected to the license number has outnumbered.", nil);
+                NSString *tMsg1 = NSLocalizedString(@"Please deactivate license on one of them, to use PDF Reader Pro on this computer", nil);
+                message = [NSString stringWithFormat:@"%@\n\n%@", tMsg0, tMsg1];
+            } else if (ActivityErrorTypeNetworkDisable == error.code) {
+                message = NSLocalizedString(@"The network is unavailable.", nil);
+            } else if (ActivityErrorTypeCDKeyExpire == error.code) {
+                message = NSLocalizedString(@"The license number expired.", nil);
+            } else if (ActivityErrorTypeInvalidInfo == error.code) {
+                message = NSLocalizedString(@"Activation error. Please try to input correct license, or contact us.", nil);
+            } else if (ActivityErrorTypeNotMatchProduct == error.code) {
+                message = NSLocalizedString(@"The license number is wrong, please input right license which is for this app.", nil);
+            } else if (ActivityErrorTypeFormatError == error.code) {
+                message = NSLocalizedString(@"Error license. Please enter an AI license.", nil);
+            }
+
+            if ((ActivityErrorTypeUnknow == error.code) || (ActivityErrorTypeOutNumber == error.code) || (ActivityErrorTypeInvalidInfo == error.code)) {
+                NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
+                                                 defaultButton:NSLocalizedString(@"Contact Us", nil)
+                                               alternateButton:NSLocalizedString(@"Try Again", nil)
+                                                   otherButton:nil
+                                     informativeTextWithFormat:message, nil];
+                if ([alert runModal]) {
+                    [blockSelf verificationFeedback];
+                }
+            } else {
+                if (ActivityErrorTypeNetworkDisable == error.code) {
+                    NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
+                                                     defaultButton:NSLocalizedString(@"OK", nil)
+                                                   alternateButton:nil
+                                                       otherButton:nil
+                                         informativeTextWithFormat:@"", nil];
+                    
+                    NSButton *accessryBtn = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];
+                    accessryBtn.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin;
+                    accessryBtn.bezelStyle = NSBezelStyleRegularSquare;
+                    accessryBtn.bordered = NO;
+                    accessryBtn.target = self;
+                    accessryBtn.action = @selector(accessryBtnClicked:);
+                    NSMutableAttributedString *mutAttrString = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Please make sure your internet connection is available.", nil)];
+                    [mutAttrString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:12] range:NSMakeRange(0, [mutAttrString length])];
+                    [mutAttrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [mutAttrString length])];
+                    [mutAttrString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Interactive_M0] range:NSMakeRange(0, [mutAttrString length])];
+                    
+                    accessryBtn.attributedTitle = mutAttrString;
+                    NSRect rect = [mutAttrString boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
+                    CGRect frame = accessryBtn.frame;
+                    frame.size.height = rect.size.height;
+                    accessryBtn.frame = frame;
+                    alert.accessoryView = accessryBtn;
+                    
+                    [alert runModal];
+                } else {
+                    NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
+                                                     defaultButton:NSLocalizedString(@"Try Again", nil)
+                                                   alternateButton:nil
+                                                       otherButton:nil
+                                         informativeTextWithFormat:message, nil];
+                    [alert runModal];
+                }
+            }
+        } else {
+            blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
+            blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congratulations! You can start using PDF Reader Pro AI features.", nil);
+            [blockSelf setContentView:blockSelf.activityAlertViewController.view];
+        }
+    }];
+}
+
 - (void)verificationActivate:(NSString *)license {
     if (license.length <= 0) {
         return;
     }
+    if ([license hasPrefix:@"AI-"]) {
+        NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
+                                         defaultButton:NSLocalizedString(@"Try Again", nil)
+                                       alternateButton:nil
+                                           otherButton:nil
+                             informativeTextWithFormat:NSLocalizedString(@"For AI license code, please activate it via 'My AI Credit' - 'Enter AI License' in the upper right corner.", nil), nil];
+        [alert runModal];
+        return;
+    }
     if (![self isConnectionAvailable]) {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
                                          defaultButton:NSLocalizedString(@"OK", nil)
@@ -589,7 +730,7 @@ static KMVerificationWindowController *_currentWindowController = nil;
             }
         } else {
             blockSelf.activityAlertViewController.alertTitle = NSLocalizedString(@"Successful Activation!", nil);
-            blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congrats! You can start enjoying the advanced features of PDF Reader Pro.", nil);
+            blockSelf.activityAlertViewController.alertMessage = NSLocalizedString(@"Congrats! You are eligible to enjoy all advanced features (excluding AI) in PDF Reader Pro.", nil);
             [blockSelf setContentView:blockSelf.activityAlertViewController.view];
         }
     }];