Skip to content
dschadow edited this page Dec 23, 2014 · 3 revisions

Although it might look like JCrypTool does not have a workspace (there is no way for the user to specify a folder), JCrypTool does have one. The name of this folder is .jcryptool and it is located in the user home directory. The . at the beginning hides this folder per default. The normal user doesn't need to care about this folder, but this is the right place for you as a developer to persist user data.

Preferences

The easiest way to persist user data is to use the preferences. As everything else, JCrypTool preferences are Eclipse based. Stick to this and JCrypTool (Eclipse) takes care of persisting this user data in the .jcryptool/.metadata folder. The structure in this folder gets confusing, but luckily you do not have to care about that. Just use the methods offered by Eclipse for loading and storing preferences. Look around in JCrypTool; there are plenty of examples on how to do that!

Implementation sample for the preferences

Files

Sometimes storing user data as preferences is not an option. You need a file. This is possible too, and there are no limitations on where you can store these files. But why not use the workspace folder .jcryptool for that too? One place for all our files. And this folder will always be there, the JCrypTool runtime takes care of that. So there is absolutely no need for you to do an exists() check for this folder or to even try to create it.

Storing files in the installation directory (jcryptool, the one without the . at the beginning which contains all plug-ins) is not a good idea. This will cause trouble on multi user systems and it might even be write protected.

Discovering the Workspace

// receiving the workspace
IWorkspace workspace = ResourcesPlugin.getWorkspace();
// receiving the workspace path
String path = workspace.getRoot().getLocation().toString();

// the short way, combined in a single line
String path = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();

The classes IWorkspace and the ResourcesPlugin are contained in the org.eclipse.core.resources plug-in. Simply add this plug-in to your dependencies list and you are good to go. Use always the code shown above, do not hard code the path as the workspace folder might be located somewhere else in the future.

The returned path will look like /Users/username/.jcryptool on OS X or C:\Documents and Settings\username.jcryptool on Windows. It is wise to create a folder inside the .jcryptool folder which is related to your plug-in or indicates the type of files you want to store in there. Examples are .jcryptool/alphabets for the classic alphabet.xml files or .jcryptool/flexiprovider for FlexiProvider related data. Again, the .jcryptool folder is created automatically the moment JCrypTool is being started. Even if the user deletes this folder it will be recreated the next time JCrypTool is being started. Any folder in .jcryptool on the other side is optional, except the .metadata folder. So verify that your folder(s) and your file(s) exist before using it. And do not misuse the .metadata folder for storing your files, .metadata is for preferences and logs only!

Implementation sample for storing files in the workspace folder