-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e965ad0
Showing
3 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Xcode | ||
.DS_Store | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
*.xcworkspace | ||
!default.xcworkspace | ||
xcuserdata | ||
profile | ||
*.moved-aside | ||
DerivedData | ||
.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,281 @@ | ||
// !$*UTF8*$! | ||
{ | ||
archiveVersion = 1; | ||
classes = { | ||
}; | ||
objectVersion = 50; | ||
objects = { | ||
|
||
/* Begin PBXBuildFile section */ | ||
46AD11D820864B9600FCCCB6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 46AD11D720864B9600FCCCB6 /* main.m */; }; | ||
/* End PBXBuildFile section */ | ||
|
||
/* Begin PBXCopyFilesBuildPhase section */ | ||
46AD11D220864B9600FCCCB6 /* CopyFiles */ = { | ||
isa = PBXCopyFilesBuildPhase; | ||
buildActionMask = 2147483647; | ||
dstPath = /usr/share/man/man1/; | ||
dstSubfolderSpec = 0; | ||
files = ( | ||
); | ||
runOnlyForDeploymentPostprocessing = 1; | ||
}; | ||
/* End PBXCopyFilesBuildPhase section */ | ||
|
||
/* Begin PBXFileReference section */ | ||
46AD11D420864B9600FCCCB6 /* BCurrency */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BCurrency; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
46AD11D720864B9600FCCCB6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; | ||
/* End PBXFileReference section */ | ||
|
||
/* Begin PBXFrameworksBuildPhase section */ | ||
46AD11D120864B9600FCCCB6 /* Frameworks */ = { | ||
isa = PBXFrameworksBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXFrameworksBuildPhase section */ | ||
|
||
/* Begin PBXGroup section */ | ||
46AD11CB20864B9500FCCCB6 = { | ||
isa = PBXGroup; | ||
children = ( | ||
46AD11D620864B9600FCCCB6 /* BCurrency */, | ||
46AD11D520864B9600FCCCB6 /* Products */, | ||
); | ||
sourceTree = "<group>"; | ||
}; | ||
46AD11D520864B9600FCCCB6 /* Products */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
46AD11D420864B9600FCCCB6 /* BCurrency */, | ||
); | ||
name = Products; | ||
sourceTree = "<group>"; | ||
}; | ||
46AD11D620864B9600FCCCB6 /* BCurrency */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
46AD11D720864B9600FCCCB6 /* main.m */, | ||
); | ||
path = BCurrency; | ||
sourceTree = "<group>"; | ||
}; | ||
/* End PBXGroup section */ | ||
|
||
/* Begin PBXNativeTarget section */ | ||
46AD11D320864B9600FCCCB6 /* BCurrency */ = { | ||
isa = PBXNativeTarget; | ||
buildConfigurationList = 46AD11DB20864B9600FCCCB6 /* Build configuration list for PBXNativeTarget "BCurrency" */; | ||
buildPhases = ( | ||
46AD11D020864B9600FCCCB6 /* Sources */, | ||
46AD11D120864B9600FCCCB6 /* Frameworks */, | ||
46AD11D220864B9600FCCCB6 /* CopyFiles */, | ||
); | ||
buildRules = ( | ||
); | ||
dependencies = ( | ||
); | ||
name = BCurrency; | ||
productName = BCurrency; | ||
productReference = 46AD11D420864B9600FCCCB6 /* BCurrency */; | ||
productType = "com.apple.product-type.tool"; | ||
}; | ||
/* End PBXNativeTarget section */ | ||
|
||
/* Begin PBXProject section */ | ||
46AD11CC20864B9500FCCCB6 /* Project object */ = { | ||
isa = PBXProject; | ||
attributes = { | ||
LastUpgradeCheck = 0930; | ||
ORGANIZATIONNAME = Yach; | ||
TargetAttributes = { | ||
46AD11D320864B9600FCCCB6 = { | ||
CreatedOnToolsVersion = 9.3; | ||
}; | ||
}; | ||
}; | ||
buildConfigurationList = 46AD11CF20864B9500FCCCB6 /* Build configuration list for PBXProject "BCurrency" */; | ||
compatibilityVersion = "Xcode 9.3"; | ||
developmentRegion = en; | ||
hasScannedForEncodings = 0; | ||
knownRegions = ( | ||
en, | ||
); | ||
mainGroup = 46AD11CB20864B9500FCCCB6; | ||
productRefGroup = 46AD11D520864B9600FCCCB6 /* Products */; | ||
projectDirPath = ""; | ||
projectRoot = ""; | ||
targets = ( | ||
46AD11D320864B9600FCCCB6 /* BCurrency */, | ||
); | ||
}; | ||
/* End PBXProject section */ | ||
|
||
/* Begin PBXSourcesBuildPhase section */ | ||
46AD11D020864B9600FCCCB6 /* Sources */ = { | ||
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
46AD11D820864B9600FCCCB6 /* main.m in Sources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXSourcesBuildPhase section */ | ||
|
||
/* Begin XCBuildConfiguration section */ | ||
46AD11D920864B9600FCCCB6 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
CLANG_ANALYZER_NONNULL = YES; | ||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; | ||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; | ||
CLANG_CXX_LIBRARY = "libc++"; | ||
CLANG_ENABLE_MODULES = YES; | ||
CLANG_ENABLE_OBJC_ARC = YES; | ||
CLANG_ENABLE_OBJC_WEAK = YES; | ||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; | ||
CLANG_WARN_BOOL_CONVERSION = YES; | ||
CLANG_WARN_COMMA = YES; | ||
CLANG_WARN_CONSTANT_CONVERSION = YES; | ||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; | ||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | ||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | ||
CLANG_WARN_EMPTY_BODY = YES; | ||
CLANG_WARN_ENUM_CONVERSION = YES; | ||
CLANG_WARN_INFINITE_RECURSION = YES; | ||
CLANG_WARN_INT_CONVERSION = YES; | ||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; | ||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | ||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | ||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | ||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | ||
CLANG_WARN_STRICT_PROTOTYPES = YES; | ||
CLANG_WARN_SUSPICIOUS_MOVE = YES; | ||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; | ||
CLANG_WARN_UNREACHABLE_CODE = YES; | ||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
CODE_SIGN_IDENTITY = "-"; | ||
COPY_PHASE_STRIP = NO; | ||
DEBUG_INFORMATION_FORMAT = dwarf; | ||
ENABLE_STRICT_OBJC_MSGSEND = YES; | ||
ENABLE_TESTABILITY = YES; | ||
GCC_C_LANGUAGE_STANDARD = gnu11; | ||
GCC_DYNAMIC_NO_PIC = NO; | ||
GCC_NO_COMMON_BLOCKS = YES; | ||
GCC_OPTIMIZATION_LEVEL = 0; | ||
GCC_PREPROCESSOR_DEFINITIONS = ( | ||
"DEBUG=1", | ||
"$(inherited)", | ||
); | ||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; | ||
GCC_WARN_UNDECLARED_SELECTOR = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | ||
GCC_WARN_UNUSED_FUNCTION = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
MACOSX_DEPLOYMENT_TARGET = 10.13; | ||
MTL_ENABLE_DEBUG_INFO = YES; | ||
ONLY_ACTIVE_ARCH = YES; | ||
SDKROOT = macosx; | ||
}; | ||
name = Debug; | ||
}; | ||
46AD11DA20864B9600FCCCB6 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
CLANG_ANALYZER_NONNULL = YES; | ||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; | ||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; | ||
CLANG_CXX_LIBRARY = "libc++"; | ||
CLANG_ENABLE_MODULES = YES; | ||
CLANG_ENABLE_OBJC_ARC = YES; | ||
CLANG_ENABLE_OBJC_WEAK = YES; | ||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; | ||
CLANG_WARN_BOOL_CONVERSION = YES; | ||
CLANG_WARN_COMMA = YES; | ||
CLANG_WARN_CONSTANT_CONVERSION = YES; | ||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; | ||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | ||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | ||
CLANG_WARN_EMPTY_BODY = YES; | ||
CLANG_WARN_ENUM_CONVERSION = YES; | ||
CLANG_WARN_INFINITE_RECURSION = YES; | ||
CLANG_WARN_INT_CONVERSION = YES; | ||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; | ||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | ||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | ||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | ||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | ||
CLANG_WARN_STRICT_PROTOTYPES = YES; | ||
CLANG_WARN_SUSPICIOUS_MOVE = YES; | ||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; | ||
CLANG_WARN_UNREACHABLE_CODE = YES; | ||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
CODE_SIGN_IDENTITY = "-"; | ||
COPY_PHASE_STRIP = NO; | ||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; | ||
ENABLE_NS_ASSERTIONS = NO; | ||
ENABLE_STRICT_OBJC_MSGSEND = YES; | ||
GCC_C_LANGUAGE_STANDARD = gnu11; | ||
GCC_NO_COMMON_BLOCKS = YES; | ||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; | ||
GCC_WARN_UNDECLARED_SELECTOR = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | ||
GCC_WARN_UNUSED_FUNCTION = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
MACOSX_DEPLOYMENT_TARGET = 10.13; | ||
MTL_ENABLE_DEBUG_INFO = NO; | ||
SDKROOT = macosx; | ||
}; | ||
name = Release; | ||
}; | ||
46AD11DC20864B9600FCCCB6 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
CODE_SIGN_STYLE = Manual; | ||
DEVELOPMENT_TEAM = ""; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
PROVISIONING_PROFILE_SPECIFIER = ""; | ||
}; | ||
name = Debug; | ||
}; | ||
46AD11DD20864B9600FCCCB6 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
CODE_SIGN_STYLE = Manual; | ||
DEVELOPMENT_TEAM = ""; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
PROVISIONING_PROFILE_SPECIFIER = ""; | ||
}; | ||
name = Release; | ||
}; | ||
/* End XCBuildConfiguration section */ | ||
|
||
/* Begin XCConfigurationList section */ | ||
46AD11CF20864B9500FCCCB6 /* Build configuration list for PBXProject "BCurrency" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
46AD11D920864B9600FCCCB6 /* Debug */, | ||
46AD11DA20864B9600FCCCB6 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
46AD11DB20864B9600FCCCB6 /* Build configuration list for PBXNativeTarget "BCurrency" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
46AD11DC20864B9600FCCCB6 /* Debug */, | ||
46AD11DD20864B9600FCCCB6 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
/* End XCConfigurationList section */ | ||
}; | ||
rootObject = 46AD11CC20864B9500FCCCB6 /* Project object */; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// main.m | ||
// BCurrency | ||
// | ||
// Created by Blankwonder on 2018/4/17. | ||
// Copyright © 2018 Yach. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:argc]; | ||
for (int i = 0; i < argc; i++) { | ||
[array addObject:[NSString stringWithUTF8String:argv[i]]]; | ||
} | ||
|
||
NSString *execName = [(NSString *)array.firstObject lastPathComponent]; | ||
NSArray *comps = [execName componentsSeparatedByString:@"-"]; | ||
|
||
NSString *from = comps.count == 2 ? comps.lastObject : @"USD"; | ||
NSString *to = @"CNY"; | ||
|
||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://free.currencyconverterapi.com/api/v5/convert?q=%@_%@&compact=ultra", from, to]]; | ||
|
||
NSString *cachedResultPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"BCurrency_%@%@", from, to]]; | ||
|
||
NSData *data; | ||
if ([[NSFileManager defaultManager] fileExistsAtPath:cachedResultPath] && -[[NSFileManager defaultManager] attributesOfItemAtPath:cachedResultPath error:nil].fileModificationDate.timeIntervalSinceNow < 12 * 3600) { | ||
data = [NSData dataWithContentsOfFile:cachedResultPath]; | ||
} else { | ||
NSURLResponse *response = nil; | ||
NSError *error = nil; | ||
data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:&response error:&error]; | ||
|
||
if (data.length == 0 || error) { | ||
NSDictionary *output = @{@"items": @[@{@"title": [NSString stringWithFormat:@"Error: %@", error.localizedDescription]}]}; | ||
|
||
NSData *outputData = [NSJSONSerialization dataWithJSONObject:output options:0 error:nil]; | ||
|
||
NSFileHandle *sout = [NSFileHandle fileHandleWithStandardOutput]; | ||
[sout writeData:outputData]; | ||
return 0; | ||
} | ||
|
||
[data writeToFile:cachedResultPath atomically:YES]; | ||
} | ||
|
||
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; | ||
|
||
double value = [(NSString *)json.allValues.firstObject doubleValue]; | ||
double source = [array.lastObject doubleValue]; | ||
|
||
// {"items": [ | ||
// { | ||
// "uid": "desktop", | ||
// "type": "file", | ||
// "title": "Desktop", | ||
// "subtitle": "~/Desktop", | ||
// "arg": "~/Desktop", | ||
// "autocomplete": "Desktop", | ||
// "icon": { | ||
// "type": "fileicon", | ||
// "path": "~/Desktop" | ||
// } | ||
// } | ||
// ]} | ||
|
||
NSDictionary *output = @{@"items": @[@{@"subtitle": [NSString stringWithFormat:@"%@/%@ %g", from, to, value], | ||
@"title": [NSString stringWithFormat:@"%g", value * source], | ||
@"arg": [NSString stringWithFormat:@"%g", value * source] | ||
}]}; | ||
|
||
NSData *outputData = [NSJSONSerialization dataWithJSONObject:output options:0 error:nil]; | ||
|
||
NSFileHandle *sout = [NSFileHandle fileHandleWithStandardOutput]; | ||
[sout writeData:outputData]; | ||
} | ||
return 0; | ||
} |