123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // KMTools_OC.m
- // PDF Master
- //
- // Created by tangchao on 2023/3/27.
- //
- #import "KMTools_OC.h"
- #import <AppKit/AppKit.h>
- @implementation KMTools_OC
- + (BOOL)isDefaultRoleHandlerForContentType:(NSString*)fileExtension {
- NSString *app = (NSString*)CFBridgingRelease(LSCopyDefaultRoleHandlerForContentType((CFStringRef)CFBridgingRetain([self UTIforFileExtension:fileExtension]),
- kLSRolesAll));
- if ([app isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) {
- return YES;
- }
- return NO;
- }
- + (BOOL)setMyselfAsDefaultApplicationForFileExtension:(NSString *) fileExtension {
- OSStatus returnStatus = LSSetDefaultRoleHandlerForContentType ((CFStringRef)CFBridgingRetain([self UTIforFileExtension:fileExtension]),
- kLSRolesAll,
- (CFStringRef) CFBridgingRetain([[NSBundle mainBundle] bundleIdentifier]));
- if (returnStatus != 0) {
- return NO;
- }
- return YES;
- }
- + (BOOL) setPreviewAsDefaultApplicationForFileExtension:(NSString *) fileExtension {
- OSStatus returnStatus = LSSetDefaultRoleHandlerForContentType ((CFStringRef)CFBridgingRetain([self UTIforFileExtension:fileExtension]),
- kLSRolesAll,
- (CFStringRef)@"com.apple.Preview");
- if (returnStatus != 0) {
- return NO;
- }
- return YES;
- }
- #pragma mark --SetDefaultRoleHandlerForContentType
- + (NSString *)UTIforFileExtension:(NSString *) extension {
- NSString * UTIString = (NSString *)CFBridgingRelease(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
- (CFStringRef)CFBridgingRetain(extension),
- NULL));
-
- return UTIString;
- }
- + (KMAppTarget)getAppTarget {
- // VERSION_DMG=1
- // VERSION_FREE=1
- // VERSION_PRO=1
- #if VERSION_FREE
- return KMAppTargetFree;
- #endif
- #if VERSION_PRO
- return KMAppTargetPro;
- #endif
- #if VERSION_DMG
- return KMAppTargetDMG;
- #endif
- return KMAppTargetFree;
- }
- @end
- @implementation KMPageSizeTool
- + (NSString *)conversionWithUnit:(NSString *)unit value:(CGFloat)value
- {
- CGFloat f = value;
- if ([unit isEqualToString:@"cm"]) {
- f = value/10.0;
- } else if([unit isEqualToString:@"in"]){
- f = value/25.4;
- } else {
- f = value;
- }
- if (fmodf(f, 1)==0) {//如果有一位小数点
- return [NSString stringWithFormat:@"%.0f",f];
- } else if (fmodf(value*10, 1)==0) {//如果有两位小数点
- return [NSString stringWithFormat:@"%.1f",f];
- } else {
- return [NSString stringWithFormat:@"%.2f",f];
- }
- }
- @end
|