Search in sources :

Example 1 with FinderLocal

use of ch.cyberduck.core.local.FinderLocal in project cyberduck by iterate-ch.

the class ApplicationSupportDirectoryFinder method find.

@Override
public Local find() {
    final NSArray directories = FoundationKitFunctions.library.NSSearchPathForDirectoriesInDomains(FoundationKitFunctions.NSSearchPathDirectory.NSApplicationSupportDirectory, FoundationKitFunctions.NSSearchPathDomainMask.NSUserDomainMask, true);
    final String application = preferences.getProperty("application.name");
    if (directories.count().intValue() == 0) {
        log.error("Failed searching for application support directory");
        return new FinderLocal("~/Library/Application Support", application);
    } else {
        final String directory = directories.objectAtIndex(new NSUInteger(0)).toString();
        if (log.isInfoEnabled()) {
            log.info(String.format("Found application support directory in %s", directory));
        }
        final Local folder = new FinderLocal(directory, application);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Use folder %s for application support directory", folder));
        }
        return folder;
    }
}
Also used : FinderLocal(ch.cyberduck.core.local.FinderLocal) NSArray(ch.cyberduck.binding.foundation.NSArray) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger)

Example 2 with FinderLocal

use of ch.cyberduck.core.local.FinderLocal in project cyberduck by iterate-ch.

the class BundleApplicationResourcesFinder method bundle.

public NSBundle bundle() {
    if (cached != null) {
        return cached;
    }
    if (log.isInfoEnabled()) {
        log.info("Loading application bundle resources");
    }
    final NSBundle main = NSBundle.mainBundle();
    if (null == main) {
        cached = null;
    } else {
        final Local executable = new FinderLocal(main.executablePath());
        cached = this.bundle(main, executable);
    }
    return cached;
}
Also used : NSBundle(ch.cyberduck.binding.foundation.NSBundle) FinderLocal(ch.cyberduck.core.local.FinderLocal) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local)

Example 3 with FinderLocal

use of ch.cyberduck.core.local.FinderLocal in project cyberduck by iterate-ch.

the class LibraryLogDirectoryFinder method find.

@Override
public Local find() {
    final NSArray directories = FoundationKitFunctions.library.NSSearchPathForDirectoriesInDomains(FoundationKitFunctions.NSSearchPathDirectory.NSLibraryDirectory, FoundationKitFunctions.NSSearchPathDomainMask.NSUserDomainMask, true);
    final String application = preferences.getProperty("application.name");
    if (directories.count().intValue() == 0) {
        log.error("Failed searching for library directory");
        return new FinderLocal("~/Library/Logs", application);
    } else {
        final String directory = directories.objectAtIndex(new NSUInteger(0)).toString();
        if (log.isInfoEnabled()) {
            log.info(String.format("Found library directory in %s", directory));
        }
        final Local folder = new FinderLocal(new FinderLocal(directory, "Logs"), application);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Use folder %s for log directory", folder));
        }
        return folder;
    }
}
Also used : FinderLocal(ch.cyberduck.core.local.FinderLocal) NSArray(ch.cyberduck.binding.foundation.NSArray) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger)

Example 4 with FinderLocal

use of ch.cyberduck.core.local.FinderLocal in project cyberduck by iterate-ch.

the class SecurityApplicationGroupSupportDirectoryFinder method find.

@Override
public Local find() {
    final NSFileManager manager = NSFileManager.defaultManager();
    if (manager.respondsToSelector(Foundation.selector("containerURLForSecurityApplicationGroupIdentifier:"))) {
        final NSURL group = manager.containerURLForSecurityApplicationGroupIdentifier(identifier);
        if (null == group) {
            log.warn("Missing com.apple.security.application-groups in sandbox entitlements");
        } else {
            // You should organize the contents of this directory in the same way that any other Library folder is organized
            final String application = PreferencesFactory.get().getProperty("application.datafolder.name");
            final Local folder = new FinderLocal(String.format("%s/Library/Application Support", group.path()), application);
            final Local previous = new ApplicationSupportDirectoryFinder().find();
            if (previous.exists() && !previous.isSymbolicLink()) {
                log.warn(String.format("Migrate application support folder from %s to %s", previous, folder));
                // Rename folder recursively
                try {
                    FileUtils.copyDirectory(new File(previous.getAbsolute()), new File(folder.getAbsolute()));
                    log.warn(String.format("Move application support folder %s to Trash", previous));
                    try {
                        final Trash trash = LocalTrashFactory.get();
                        trash.trash(previous);
                        final Symlink symlink = LocalSymlinkFactory.get();
                        symlink.symlink(previous, folder.getAbsolute());
                    } catch (AccessDeniedException e) {
                        log.warn(String.format("Failure cleaning up previous application support directory. %s", e.getMessage()));
                    }
                } catch (IOException e) {
                    log.warn(String.format("Failure migrating %s to security application group directory %s. %s", previous, folder, e.getMessage()));
                }
            } else {
                log.debug(String.format("No previous application support folder found in %s", previous));
            }
            return folder;
        }
    }
    log.warn("Missing support for security application groups. Default to application support directory");
    // Fallback for 10.7 and earlier
    return new ApplicationSupportDirectoryFinder().find();
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) FinderLocal(ch.cyberduck.core.local.FinderLocal) Symlink(ch.cyberduck.core.local.features.Symlink) NSFileManager(ch.cyberduck.binding.foundation.NSFileManager) NSURL(ch.cyberduck.binding.foundation.NSURL) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local) IOException(java.io.IOException) File(java.io.File) Trash(ch.cyberduck.core.local.features.Trash)

Example 5 with FinderLocal

use of ch.cyberduck.core.local.FinderLocal in project cyberduck by iterate-ch.

the class SharedFileListApplicationLoginRegistryTest method testRegister.

@Test
@Ignore
public void testRegister() {
    final SharedFileListApplicationLoginRegistry registry = new SharedFileListApplicationLoginRegistry(new LaunchServicesApplicationFinder());
    final Application application = new Application("ch.sudo.cyberduck");
    assertTrue(registry.register(application));
    assertTrue(new FinderSidebarService(SidebarService.List.login).contains(new FinderLocal(NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier(application.getIdentifier()))));
    assertTrue(registry.unregister(application));
}
Also used : LaunchServicesApplicationFinder(ch.cyberduck.core.local.LaunchServicesApplicationFinder) FinderLocal(ch.cyberduck.core.local.FinderLocal) Application(ch.cyberduck.core.local.Application) FinderSidebarService(ch.cyberduck.core.local.FinderSidebarService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FinderLocal (ch.cyberduck.core.local.FinderLocal)10 Local (ch.cyberduck.core.Local)6 Test (org.junit.Test)4 NSImage (ch.cyberduck.binding.application.NSImage)3 NSArray (ch.cyberduck.binding.foundation.NSArray)2 NSBundle (ch.cyberduck.binding.foundation.NSBundle)2 Ignore (org.junit.Ignore)2 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)2 NSFileManager (ch.cyberduck.binding.foundation.NSFileManager)1 NSURL (ch.cyberduck.binding.foundation.NSURL)1 Path (ch.cyberduck.core.Path)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 Application (ch.cyberduck.core.local.Application)1 FinderSidebarService (ch.cyberduck.core.local.FinderSidebarService)1 LaunchServicesApplicationFinder (ch.cyberduck.core.local.LaunchServicesApplicationFinder)1 Symlink (ch.cyberduck.core.local.features.Symlink)1 Trash (ch.cyberduck.core.local.features.Trash)1 File (java.io.File)1 IOException (java.io.IOException)1