Last updated: May 12, 2014

 

Index

  1. Introduction

         Downloading sample package

  2. Quick workflow
  3. Opening and reading resource files

         Reading graphic assets
         Using dropbox
         Reading audio assets

  4. Combining assets into NSData

         Save File Names
         Show Sample Code

  5. Recovering individual assets

         Graphics for OS X
         Graphics for iOS
         Audio for OS X
         Audio for iOS

  6. Saving progress

  7. Preferences

         7a) General settings
         7b) Folders

  8. FAQ


 

1. Introduction: Lockade is a desktop application that lets you combine the same type of resource files into one NSData file so that casual users cannot harvest your resources like audio and image files simply by examining the application package.  For example, you can combine all your JPEG, PNG, TIFF files into one NSData file.  By combining these graphic files into a single file, casual users cannot use Preview to view individual ones.  If you don't, anyone can open the application package, navigating to the Resources folder and hand-picking resources they want.

 

Mac software Lockade

Screenshot 1-01

 

Imagine a situation where you've spent tens of hours designing Mahjong tiles for your game.  In fact, Screenshot 1-01 shows three dozen PNG images for Mahjong tiles put in an Xcode project.  Despite your effort, a casual user could harvest these files by just opening the application package, navigating to the Resources folder.  (See Screenshot 1-02.)

 

Mac software Lockade

Screenshot 1-02

 

So, again, what you could do in this situation is combining Mahjong images into a single NSData file, using Lockade.  (See Screenshot 1-03.)  Put that NSData file in your Xcode.  It would take you just several lines to recover original images from NSData.  Similarly, you can combine a number of audio files into a single NSData file.

 

Mac software Lockade

Screenshot 1-03

 

You can download a zip package that contains sample Xcode projects for Mac OS X and iOS.  Click here.

 

2. Quick workflow: Lockade's workflow goes as follows.

 

  1. Use either radio buttons to set a file type, Graphics or Audio.
  2. Choose Open Assets under File to open and read resourece files.
  3. Choose Export Data under File to combine assets appearing in the list into a single file.
  4. Save current progress as a project file.  You can double-click on a project file to restore a file list.
  5. Put the resulting NSData file in your Xcode project.
  6. While the Output window is open, select the name of the file you exported last time and choose Show Sample Code under Output to get sample code.

 

3. Opening and reading resource files: There are two types of files that Lockade work with.  You can work on one type of files at a time.  In other words, Lockade won't let you list audio and graphic files simultaneously.

 

Mac software Lockade

Screenshot 1-01

Mac software Lockade

Screenshot 1-02

 

If you want to combine image files into one, first, click on the Graphics radiobutton.  (See Screenshot 1-01.)  Then choose Open Assets under File.  You can also click on the 4th toolbar button from the left end for the same purpose.  You will then be prompted to select image files as shown in Screenshot 1-02.  If you want to select multiple files at a time, hold down the Shift key to select files.  Supported graphic formats are BMP, GIF, JPEG, JPEG 2000, PDF, PNG, PSD and TIFF.  Finally, press RETURN or click on the Open button.  Then your files will be listed accordingly.

Taking a quick look at the list on the main application window, file icons appear on the first column.  (See Screenshot 1-03.)  Appearing on the second column are file names.  You have file extensions on the third column.  The fourth column shows image dimensions.  Finally, the fifth column shows file paths.  There's a color label in blue right below the list.  It indicates the number of files in the list.

 

Mac software Lockade

Screenshot 1-03

Mac software Lockade

Screenshot 1-04

 

If you want to remove any of them from the list, choose one or more to remove.  Then press the Delete key.  You can also choose Remove File under List.  And you will be prompted for confirmation.  (See Screenshot 1-04.)  So click on Remove to proceed.  Similarly, if you want to clear the list, choose Remove All Files under List.

If you have quick access to your resource files, you can use a drop box to read them at a time.  Choose Open Assets With Dropbox under File or click on the 5th toolbar button from the left end to open a drop box.  Then just drag and drop image files onto the drop box as shown in Screenshot 1-05.

 

Mac software Lockade

Screenshot 1-05

Mac software Lockade

Screenshot 1-06

 

If you want to work on audio files, make sure you click on the Audio radiobutton, first.  Then choose Open Assets under File to open and read audio files.  Supported file types are AIF, CAF, FLAC, M4A, MP3, OGG and WAV.  As shown in Screenshot 1-06, you can of course use the drop box to read audio files as well.

Note that the order of appearance in the list matters.  Individual files that you recover through Xcode will be referred to as array elements.  (We will get to that in detail soon.)  Therefore, if necessary, drag rows to move up and down to change the order of appearance.

 

4. Combining assets into NSData: If everything is in order, choose Export Data To under File.  (See Screenshot 1-07.)  You can also click on the rightmost toolbar button for the same purpose.  Then you will be prompted to name a data file.  (See Screenshot 1-08.)  You can name a data file with or without a file extension.  That's up to you.  You may even add a fake file extension to a data file like jpg or png for Graphics (or caf or wav for Audio) to deceive casual harvesters when in fact they can't open them with a graphic viewer (or QuickTime for audio).

 

Mac software Lockade

Screenshot 1-07

Mac software Lockade

Screenshot 1-08

 

Finally, press RETURN or click on Save, and Lockade will display a modal sheet, showing progress.  (See Screenshot 1-09.)  You can abort the writing process by clicking on the Cancel button at any time.  Yet, if you have just a few dozen assets, it'll be just the matter of 3 or 4 seconds, and Lockade will finish writing data to an NSData file.

 

Mac software Lockade

Screenshot 1-09

Mac software Lockade

Screenshot 1-10

 

When Lockade finishes writing data to an NSData file, it will open a small, separate window.  (See Screenshot 1-10.)  Every time you export a data file, Lockade will add a new row to the list of the Output window.  Through this list, you can find out which data file has how many files for which type.  And you can save file names as a text file through this window.  (Choose Save File Names As Text and Save File Names As XML under Output.)

Next, select a row on the Output list and choose Show Sample Code under Output.  (See Screenshot 1-11.)  And another seperate window will open, showing you sample code that you can use with Xcode to recover individual images or sounds.  (See Screenshot 1-12.)

 

Mac software Lockade

Screenshot 1-11

Mac software Lockade

Screenshot 1-12

 

5. Recovering individual assets: The whole purpose of converting a series of resource files into a single NSData file is to keep casual users from harvesting assets by opening the application package.  At the same time, you must be easily able to recover individual assets from the same NSData file through Xcode.

Graphics for OS X

First of all, drag and drop the NSData file you have created onto the left sidebar of your Xcode project.  We need to read this data file in order to recover individual graphic assets.

 

Mac software Lockade

Screenshot 1-13

Mac software Lockade

Screenshot 1-14

 

If you want to recover images for an OS X application, try adding NSImageView as an IBOutlet to a header file.  (See Screenshot 1-13.)  Switch to an implementation file.

Let's first read the NSData file.  We use the pathForResource method to get the path to the data file in the project.  Remember, if you set a file extension to your data file, whether it's fake a not, you need to insert that exact file extesnion to 'ofType.'  Next, in order to read file content as NSData, use the dataWithContentsOfFile method of NSData.  Next, convert NSData into an array with the unarchiveObjectWithData method of NSKeyedUnarchiver.  Now, you have your individual images in an array.  If you want to recover the very first image that listed, then you will get this image as NSImage by setting the objectAtIndex to 0.  The following shows the entire code for the implementation file.

 

NSString *path = [[NSBundle mainBundle] pathForResource:@"AllImages" ofType:@""];
NSData *data = [NSData dataWithContentsOfFile:path];
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSImage *img = [[NSImage alloc] initWithData:[array objectAtIndex:0]];
imageView.image = img;

 

Graphics for iOS

There is little departure from the above.  You have UIImage instead of NSImage.  The following is sample code.

 

NSString *path = [[NSBundle mainBundle] pathForResource:@"Untitled1" ofType:@""];
NSData *data = [NSData dataWithContentsOfFile:path];
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
UIImage *img = [[UIImage alloc] initWithData:[array objectAtIndex:0]];
imageView.image = img; // imageView is an UIImageView IB outlet.

 

Audio for OS X

There are a few different ways of playing back audio files.  In our case, we use AVAudioPlayer.  So we need to first import AVFoundation.  Write #import <AVFoundation/AVFoundation.h> at the top of a header file.  (See Screenshot 1-15.)  Also, add AVAudioPlayer as an instance variable.  Furthermore, add an AVAudioPlayer variable as a strong property to a header file.

 

Mac software Lockade

Screenshot 1-15

Mac software Lockade

Screenshot 1-16

 

Switching to an implementation file, read the data file as before.  Then set an individual audio asset to AVAudioPlayer with its initWithData method.  The following is the entire code.

 

NSString *path = [[NSBundle mainBundle] pathForResource:@"AllSounds" ofType:@""];
NSData *data = [NSData dataWithContentsOfFile:path];
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
audioPlayer = [[AVAudioPlayer alloc] initWithData:[array objectAtIndex:0] error:NULL];
[audioPlayer play];

 

Audio for iOS

The same code as above serves for iOS as well.  (See Screenshot 1-16.)

 

Sample Xcode projects

Click here to download sample XCode projects.  This Zip file contains two Xcode projects, one for OS X and one for iOS.

 

6. Saving progress: Lockade lets you save current progress as a project file so that you can modify the file list and then export a data file whenever necessary.  In order to save progress, just choose Save As Project under File.  You can also click on the 3rd toolbar button with a blue floppy disk.  Then you will be prompted to name a file.  (See Screenshot 1-17.)  The file extension is lkd.  If you want to recover progress, just double-click on a file you've created.  You can also choose Open Project under File or click on the 2nd toolbar button from the left end.  If you do, a modal sheet will briefly appear.  (See Screenshot 1-18.)

 

Mac software Lockade

Screenshot 1-17

Mac software Lockade

Screenshot 1-18

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<< Previous page   Next page >>