Skip to content

Commit e6e364c

Browse files
committed
Clean up
1 parent 4a8c191 commit e6e364c

File tree

3 files changed

+16
-62
lines changed

3 files changed

+16
-62
lines changed

Dash/DHAppDelegate.m

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -115,60 +115,30 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)actualURL sour
115115
[[NSNotificationCenter defaultCenter] postNotificationName:DHPerformURLSearch object:[actualURL absoluteString]];
116116
});
117117
}
118-
else if([[actualURL pathExtension] caseInsensitiveCompare:@".docset"])
118+
else if([[actualURL pathExtension] isCaseInsensitiveEqual:@"docset"])
119119
{
120-
NSError *regexError;
121-
NSString *fileName = [[actualURL URLByDeletingPathExtension] lastPathComponent];
120+
NSError *error;
121+
NSString *fileName = [actualURL lastPathComponent];
122122
NSURL *copyToURL = [[NSURL fileURLWithPath:transfersPath] URLByAppendingPathComponent:fileName isDirectory:NO];
123-
if ([[NSFileManager defaultManager] fileExistsAtPath:copyToURL.path])
124-
{
125-
NSURL *duplicateURL = copyToURL;
126-
copyToURL = [copyToURL URLByDeletingPathExtension];
127-
NSString *fileNameWithoutExtension = [copyToURL lastPathComponent];
128-
NSString *fileExtension = [actualURL pathExtension];
129-
for (int i = 1; [[NSFileManager defaultManager] fileExistsAtPath:duplicateURL.path]; i++)
130-
{
131-
copyToURL=[[copyToURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:[NSString stringWithFormat:@"%@%i",fileNameWithoutExtension,i]];
132-
copyToURL =[copyToURL URLByAppendingPathExtension:fileExtension];
133-
duplicateURL = copyToURL;
134-
}
135-
}
136-
[[NSFileManager defaultManager] moveItemAtURL:actualURL toURL:copyToURL error:&regexError];
123+
[[NSFileManager defaultManager] removeItemAtPath:copyToURL.path error:nil];
124+
[[NSFileManager defaultManager] moveItemAtURL:actualURL toURL:copyToURL error:&error];
137125
NSString *title;
138126
NSString *message;
139-
if (regexError)
127+
if(error)
140128
{
141-
title = @"Import failed!";
142-
message = @"Could not properly import the docset. Please try again!";
143-
NSLog(@"%@", regexError.localizedDescription);
129+
title = @"Import Failed";
130+
message = @"Could not import the docset. Please try again!";
131+
NSLog(@"%@", error.localizedDescription);
144132
}
145133
else
146134
{
147-
title = @"Import successfull!";
148-
message = @"You can find the docset in the Transfer-Docset section";
135+
title = @"Import Successful";
136+
message = @"You can find the docset in Settings, under the Transfer Docsets section.";
149137
NSLog(@"Docset successfully imported");
150138
}
151139
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle: UIAlertControllerStyleAlert];
152-
[alert addAction:[UIAlertAction actionWithTitle: @"Done" style: UIAlertActionStyleDestructive handler: nil]];
153-
[[self topViewController] presentViewController: alert animated:YES completion:nil];
154-
}
155-
else
156-
{
157-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
158-
NSError *regexError;
159-
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"Inbox/.+[\\.docset]$" options:0 error:&regexError];
160-
NSArray *matches;
161-
if (regexError) {
162-
NSLog(@"%@", regexError.localizedDescription);
163-
}
164-
else
165-
{
166-
matches = [regex matchesInString:[actualURL absoluteString] options:0 range:NSMakeRange(0, [actualURL absoluteString].length)];
167-
}
168-
if (matches.count) {
169-
[self moveInboxContentsToDocuments];
170-
}
171-
});
140+
[alert addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil]];
141+
[[self topViewController] presentViewController:alert animated:YES completion:nil];
172142
}
173143
return YES;
174144
}
@@ -309,22 +279,6 @@ - (DHWindow *)window
309279
return self._window;
310280
}
311281

312-
- (void)moveInboxContentsToDocuments
313-
{
314-
NSError *fileManagerError;
315-
NSString *inboxDirectory = [NSString stringWithFormat:@"%@/Inbox", transfersPath];
316-
NSArray *inboxContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:inboxDirectory error:&fileManagerError];
317-
for (int i = 0; i != [inboxContents count]; i++)
318-
{
319-
NSString *oldPath = [NSString stringWithFormat:@"%@/%@", inboxDirectory, [inboxContents objectAtIndex:i]];
320-
NSString *newPath = [NSString stringWithFormat:@"%@/%@", transfersPath, [inboxContents objectAtIndex:i]];
321-
[[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:newPath error:&fileManagerError];
322-
if (fileManagerError) {
323-
NSLog(@"%@",fileManagerError.localizedDescription);
324-
}
325-
}
326-
}
327-
328282
- (UIViewController *)topViewController
329283
{
330284
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];

Dash/DHDocsetDownloader.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ - (BOOL)canInstallFeed:(DHFeed *)feed
708708
else if([feed.feedURL isEqualToString:@"http://kapeli.com/feeds/Apple_API_Reference.xml"])
709709
{
710710
title = @"Apple API Reference";
711-
message = @"To install the Apple API Reference docset you need to:\n\n1. Use Dash for macOS to install the Apple API Reference docset from Preferences > Downloads\n2. Go to Preferences > Docsets, right click the Apple API Reference docset and select \"Generate iOS Compatible Docset\"\n3. Transfer the resulting docset using iTunes File Sharing";
711+
message = @"To install the Apple API Reference docset you need to:\n\n1. Use Dash for macOS to install the Apple API Reference docset from Preferences > Downloads\n2. Go to Preferences > Docsets, right click the Apple API Reference docset and select \"Generate iOS Compatible Docset\"\n3. Transfer the resulting docset using iTunes File Sharing or AirDrop";
712712
}
713713
else if([feed.feedURL isEqualToString:@"http://kapeli.com/feeds/Swift.xml"])
714714
{
@@ -719,7 +719,7 @@ - (BOOL)canInstallFeed:(DHFeed *)feed
719719
{
720720
title = @"Apple API Reference";
721721
NSString *name = [[[feed.feedURL lastPathComponent] stringByDeletingPathExtension] stringByReplacingOccurrencesOfString:@"_" withString:@" "];
722-
message = [NSString stringWithFormat:@"There is no %@ docset. The documentation for %@ can be found inside the Apple API Reference docset. \n\nTo install the Apple API Reference docset you need to:\n\n1. Use Dash for macOS to install the docset from Preferences > Downloads\n2. Go to Preferences > Docsets, right click the Apple API Reference docset and select \"Generate iOS-compatible Docset\"\n3. Transfer the resulting docset using iTunes File Sharing", name, name];
722+
message = [NSString stringWithFormat:@"There is no %@ docset. The documentation for %@ can be found inside the Apple API Reference docset. \n\nTo install the Apple API Reference docset you need to:\n\n1. Use Dash for macOS to install the docset from Preferences > Downloads\n2. Go to Preferences > Docsets, right click the Apple API Reference docset and select \"Generate iOS-compatible Docset\"\n3. Transfer the resulting docset using iTunes File Sharing or AirDrop", name, name];
723723
}
724724

725725
if(title && message)

Dash/DHDocsetTransferrer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
209209

210210
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
211211

212-
NSString *text = @"You can transfer docsets using iTunes File Sharing.\n\nFor best results, docsets that are available for download should always be downloaded instead of transferred.";
212+
NSString *text = @"You can transfer docsets using iTunes File Sharing or AirDrop.\n\nFor best results, docsets that are available for download should always be downloaded instead of transferred.";
213213
NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
214214
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
215215
paragraph.alignment = NSTextAlignmentCenter;

0 commit comments

Comments
 (0)