The AASFilesystemTools framework is a very useful tool for developers whose applications work with large file heirarchies. While writing gBrowser, we discovered that keeping track of files and associated information was our #1 job, and this framework was born of that need: Each file had it’s own basic information plus the application’s metadata, plus each file’s location and status needs to be kept updated as the user or the system moves, renames, creates, or deletes them.
It’s a big job…
Even the FSEvents api made public in Leopard only does half the job – it’ll notify you that something in your heirarchy has changed, but it’s still up to you to figure out exactly where and what it was. This means keeping track of the state of each of your files and comparing that with the current state of the filesystem whenever you recieve one of those notifications. That’s a lot of work.
…and AASFilesystemTools will do it
The AASFilesystemTools framework is there to keep track of every file your app is using. It retains data about the state of every file in your heirarchy, and when something in your heriarchy changes, it will very efficiently scan the directory in question and report the specific changes to each file back to your app.
Not just filesystem updates
We make a big deal about tracking file changes because it’s a lot of work, but AASFilesystemTools isn’t a one-trick pony. The AASFilesystemTools makes it easy to efficiently read the files in a directory or recursively through a whole heirarchy – much faster than NSFileManager does (nothing magic, we just use Carbon and some unix system calls, but it’s all Cocoa on your end). The next few paragraphs will cover other important features.
AASFile objects & subclasses
AASFilesystemTools deals with AASFile objects – or whatever subclass you create. The framework ensures there’s only one unique file object per file, so AASFile subclasses are a way to efficiently reuse file-related data and metadata when your app is working on files in multiple places (such as when gBrowser is displaying the same files in the sidebar, thumbnail pane, and a slideshow). And because each file object is unique, they can be used as keys in dictionaries for faster lookup in the appropriate situation. Each file object keeps track of the current state of the file it represents with the help of the AASFileManager.
The AASFile class, and particularly the subclass AASBasicInfoFile that is also included in the framework, give oyu quick and easy access to file information, such as the file’s path, url, fsRef, file type, uti, display name, modification date, and whether it is a folder / bundle / package / application / visible / invisible / alias / symlink. Your own subclass can give you even more power.
The AASFilesystemTools framework has built-in methods to efficiently filter file objects based on certain criteria. Your app most likely doesn’t want to display ‘invisible’ files to the user; just use the AASVisibleFileFilter. Using your own filter subclasses lets you filter based on anything you want – this comes in handy combined with using your own metadata in an AASFile subclass.
With multicore machines everywhere now, threading is more important than ever. The AASFilesystemTools framework takes full advantage of NSOperationQueues and NSOperations. When you read a directory’s file listing, you can choose to do this in a background thread. If you need to scan in an entire heirarchy, the framework’s built-in method to do so can utilize threads as well, with no extra effort on your part.
Persistent file data
AASFile objects (and subclasses) are able to write persistent state data to an NSDictionary for archiving to disk. When your app wants that data back later, it can unarchive the NSDictionary and pass it to the AASFilesystemTools framework to get ahold of that AASFile object again (even if the file has moved), complete with whatever metadata the subclasses chose to store.
Best of all, it’s free
New BSD License.
Helpful code snippets
We don’t have any code snippets up yet.
The framework download includes an Xcode project for a sample app. We suggest you play with it and read the detailed examples and instructions included in the project source.
If anyone else creates an interesting project utilizing the framework’s features that they’d like to have posted here, contact us please.
Sample project is included with the default AASFilesystemTools framework download. If for some reason you don’t have it, though, here it is.
For now, read the source files in the sample app that comes with the framework download, plus the framework’s header files.