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

Dupe bundles #146

Merged
merged 7 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ print "\n";
<key>input</key>
<string>selectedtablerowsastab</string>
<key>keyEquivalent</key>
<string></string>
<string>^c</string>
<key>name</key>
<string>Copy as CSV</string>
<key>output</key>
Expand All @@ -102,6 +102,6 @@ print "\n";
<key>uuid</key>
<string>E24C4537-0AAB-4C17-B5F9-C5054CADA77C</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ proc.communicate(input=out_value)
<key>uuid</key>
<string>0314E554-3CDB-49D2-93FC-A28231AC9BB9</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ print "&lt;/table&gt;\n";
<key>uuid</key>
<string>31FD6D95-CED5-4870-9A19-5A1396216C37</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Version 1.0</string>
<integer>262144</integer>
</dict>
<key>keyEquivalent</key>
<string>^c</string>
<string></string>
<key>name</key>
<string>Copy as JSON</string>
<key>output</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ print "\n";
<integer>262144</integer>
</dict>
<key>keyEquivalent</key>
<string>^c</string>
<string></string>
<key>name</key>
<string>Copy as Wiki</string>
<key>output</key>
Expand All @@ -108,6 +108,6 @@ print "\n";
<key>uuid</key>
<string>5B20D1B9-9C60-4D9F-B51B-5F742665557E</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ UPDATE ... WHERE id IN (1,2,3,4)</string>
<key>uuid</key>
<string>3C9F6E07-DF65-44D3-B0F2-8220E9BE009C</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ print_r(goFormatVarExport(var_export(unserialize(fgets(STDIN)), TRUE)));
<key>scope</key>
<string>inputfield</string>
<key>uuid</key>
<string>8F858F4D-9DCC-488A-B01C-D9F7FA32FE32</string>
<string>4E0126ED-3AC6-4BB5-B836-5F9718FE36D5</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ print "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel mi lacus
<key>uuid</key>
<string>C73F7EA3-4CDC-4F3F-B9EE-FEED7E3F0B71</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ print "Lorem Ipsum"</string>
<key>uuid</key>
<string>8F858F4D-9DCC-488A-B01C-D9F7FA32FE32</string>
<key>isDefaultBundle</key>
<true/>
<true/>
</dict>
</plist>
31 changes: 29 additions & 2 deletions Source/SPAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1625,13 +1625,17 @@ - (IBAction)reloadBundles:(id)sender
for(NSString* bundlePath in bundlePaths) {
if([bundlePath length]) {

SPLog(@"processing path: %@",bundlePath );

NSError *error = nil;
NSArray *foundBundles = [fm contentsOfDirectoryAtPath:bundlePath error:&error];
if (foundBundles && [foundBundles count] && error == nil) {

for(NSString* bundle in foundBundles) {
if(![[[bundle pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) continue;

SPLog(@"processing bundle: %@",bundle );

foundInstalledBundles = YES;

NSString *infoPath = [NSString stringWithFormat:@"%@/%@/%@", bundlePath, bundle, SPBundleFileName];
Expand Down Expand Up @@ -1709,6 +1713,8 @@ - (IBAction)reloadBundles:(id)sender
// Check for modifications
if([cmdDataOld objectForKey:SPBundleFileDefaultBundleWasModifiedKey]) {

SPLog(@"default bundle WAS modified, duplicate, change UUID and rename menu item");

// Duplicate Bundle, change the UUID and rename the menu label
NSString *duplicatedBundle = [NSString stringWithFormat:@"%@/%@_%ld.%@", [bundlePaths objectAtIndex:0], [bundle substringToIndex:([bundle length] - [SPUserBundleFileExtension length] - 1)], (long)(random() % 35000), SPUserBundleFileExtension];
if(![[NSFileManager defaultManager] copyItemAtPath:oldBundle toPath:duplicatedBundle error:nil]) {
Expand Down Expand Up @@ -1762,7 +1768,7 @@ - (IBAction)reloadBundles:(id)sender
}
[infoAboutUpdatedDefaultBundles appendFormat:@"• %@\n", orgName];
} else {

SPLog(@"default bundle not modified, delete and ....");
// If no modifications are done simply remove the old one
if(![fm removeItemAtPath:oldBundle error:nil]) {
NSLog(@"Couldn't remove “%@” to update it", bundle);
Expand All @@ -1773,6 +1779,8 @@ - (IBAction)reloadBundles:(id)sender
}
}

SPLog(@"copy bundle from app bundle");

BOOL isDir;
NSString *newInfoPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName];
NSString *orgPath = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:1], bundle];
Expand Down Expand Up @@ -1868,9 +1876,28 @@ - (IBAction)reloadBundles:(id)sender

if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [(NSString *)[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length])
[aDict setObject:[cmdData objectForKey:SPBundleFileKeyEquivalentKey] forKey:@"key"];
// add UUID so we can check for it
if([cmdData objectForKey:SPBundleFileUUIDKey] && [(NSString *)[cmdData objectForKey:SPBundleFileUUIDKey] length])
[aDict setObject:[cmdData objectForKey:SPBundleFileUUIDKey] forKey:SPBundleFileUUIDKey];

[[bundleItems objectForKey:scope] addObject:aDict];
SPLog(@"UUID = %@", [cmdData objectForKey:SPBundleFileUUIDKey]);

BOOL __block alreadyAdded = NO;

// check UUID, only add if it's different
[bundleItems enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSArray *obj, BOOL *stop1) {
[obj enumerateObjectsUsingBlock:^(id obj2, NSUInteger idx, BOOL *stop){
if([obj2[SPBundleFileUUIDKey] isEqualToString:[aDict objectForKey:SPBundleFileUUIDKey]]){ // what if these are null? nothing happens...
SPLog(@"Already added this UUID, name = %@",[cmdData objectForKey:SPBundleFileNameKey] );
alreadyAdded = YES;
}
}];
}];

if(alreadyAdded == NO){
SPLog(@"NEW UUID, add to menu bundle, name = %@",[cmdData objectForKey:SPBundleFileNameKey] );
[[bundleItems objectForKey:scope] addObject:aDict];
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion Source/SPConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ void _SPClear(id *addr);
#define SPClear(x) _SPClear(&x)

// Stolen from Stack Overflow: http://stackoverflow.com/questions/969130
#define SPLog(fmt, ...) NSLog((@"%s:%d: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#ifdef DEBUG
# define SPLog(fmt, ...) NSLog((@"%s:%d: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
# define SPLog(...)
#endif

// See http://stackoverflow.com/questions/4415524
#define COUNT_OF(x) (NSInteger)((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
Expand Down
1 change: 1 addition & 0 deletions sequel-ace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4265,6 +4265,7 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREFIX_HEADER = "Source/Sequel-Pro.pch";
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
Expand Down