Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #190 #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions LiquidCore/src/ios/API/LCMicroService.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ + (id) serviceFromInstanceId:(NSString*)instanceId
+ (void) uninstall:(NSURL *)serviceURI
{
NSString *serviceId;
NSRange comp = [[serviceURI absoluteString] rangeOfString:@"/" options:NSBackwardsSearch];
NSString *serviceString = [serviceURI absoluteString];
NSString *bundleString = NSBundle.mainBundle.bundleURL.absoluteString;
serviceString = [serviceString stringByReplacingOccurrencesOfString:bundleString withString:@""];
NSRange comp = [serviceString rangeOfString:@"/" options:NSBackwardsSearch];
if (comp.location != NSNotFound) {
serviceId = [[serviceURI absoluteString] substringToIndex:comp.location];
serviceId = [serviceString substringToIndex:comp.location];
} else {
serviceId = [serviceURI absoluteString];
serviceId = serviceString;
}
serviceId = [serviceId stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet URLHostAllowedCharacterSet]];
Expand Down Expand Up @@ -146,12 +149,15 @@ - (id) initWithURL:(NSURL*)serviceURI delegate:(id<LCMicroServiceDelegate>)deleg
self = [super init];
if (self) {
_serviceURI = serviceURI;
NSRange comp = [[serviceURI absoluteString] rangeOfString:@"/" options:NSBackwardsSearch];
NSString *serviceString = [serviceURI absoluteString];
NSString *bundleString = NSBundle.mainBundle.bundleURL.absoluteString;
serviceString = [serviceString stringByReplacingOccurrencesOfString:bundleString withString:@""];
NSRange comp = [serviceString rangeOfString:@"/" options:NSBackwardsSearch];
if (comp.location != NSNotFound) {
serviceId_ = [[serviceURI absoluteString] substringToIndex:comp.location];
module_ = [[serviceURI absoluteString] substringFromIndex:comp.location+1];
serviceId_ = [serviceString substringToIndex:comp.location];
module_ = [serviceString substringFromIndex:comp.location+1];
} else {
serviceId_ = [serviceURI absoluteString];
serviceId_ = serviceString;
module_ = serviceId_;
}
comp = [module_ rangeOfString:@"?"];
Expand Down Expand Up @@ -187,12 +193,8 @@ - (NSError*) fetchService

if ([self.serviceURI isFileURL]) {
// Symlink file for speed
if ([fileManager fileExistsAtPath:localPath]) {
[fileManager removeItemAtPath:localPath error:&error];
}
if (error == nil) {
[fileManager createSymbolicLinkAtURL:[NSURL fileURLWithPath:localPath] withDestinationURL:self.serviceURI error:&error];
}
[fileManager removeItemAtPath:localPath error:nil];
[fileManager createSymbolicLinkAtURL:[NSURL fileURLWithPath:localPath] withDestinationURL:self.serviceURI error:&error];
self.fetched = true;
} else {
NSDate* lastModified = nil;
Expand Down Expand Up @@ -231,9 +233,7 @@ - (NSError*) fetchService
NSHTTPURLResponse *http = (NSHTTPURLResponse*)response;
error = e;
if (error == nil && http.statusCode == 200) {
if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) {
[[NSFileManager defaultManager] removeItemAtPath:localPath error:nil];
}
[[NSFileManager defaultManager] removeItemAtPath:localPath error:nil];
[[NSFileManager defaultManager] moveItemAtURL:location
toURL:[NSURL fileURLWithPath:localPath]
error:nil];
Expand All @@ -247,14 +247,10 @@ - (NSError*) fetchService
NSBundle *bundle = [NSBundle mainBundle];
NSURL *bundleURL = [[bundle resourceURL] URLByAppendingPathComponent:@"LiquidCore.bundle"];
NSURL *fileURL = [NSBundle URLForResource:bundleName withExtension:@"js" subdirectory:nil inBundleWithURL:bundleURL];
if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) {
[[NSFileManager defaultManager] removeItemAtPath:localPath error:&error];
}
if (error == nil) {
[[NSFileManager defaultManager] copyItemAtURL:fileURL
toURL:[NSURL fileURLWithPath:localPath]
error:&error];
}
[[NSFileManager defaultManager] removeItemAtPath:localPath error:nil];
[[NSFileManager defaultManager] copyItemAtURL:fileURL
toURL:[NSURL fileURLWithPath:localPath]
error:&error];
if (error == nil) {
self.fetched = true;
return;
Expand Down