Using Dropbox with Swordfish

by Ralph S Bacon (forum member Aresby) March 2012

And why you might want to

The article explains the steps required to get Dropbox to manage your Swordfish folders for backing up or sharing - the one(s) that can't be normally moved as Swordfish won't then find them.

In particular, the UserLibrary folder is normally in a fixed location (depending on your operating system). If you move it, the Swordfish compiler won't find it and you'll end up with compilation errors if you refer to any modules within that library.

What is Dropbox?

The Dropbox site states "Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily."

It's like a mini-cloud where your files get automatically copied to a private web account and then other PCs (yours or friends, family or colleagues) can get those files automatically synchronised on their own PCs. You control who sees what.

Check out their website for more information. The first 2GB are free then you start paying.

The problem with Swordfish and Dropbox

Swordfish (probably the best PIC compiler for PIC18 series microcontrollers in the world) has some fairly regimented ideas about where its files should be.

Your program files can be anywhere - that's not the problem.

It's your UserLibrary that is such a pain. Your UserLibrary is where you store those oh-so-useful routines that you use time and time again. Or you have modified a standard Swordfish module for your own needs and have placed it, as recommended, in the UserLibrary folder.

If you always work on a single PC this may not be an issue to you, as you can backup your files via some other means. But if you need to share common library files with another PC or colleague then it quickly becomes a logistical nightmare.

This article shows you how to move the Swordfish UserLibrary into the Dropbox folder (as a subfolder) without Swordfish noticing - and without you ending up with compilation errors because Swordfish can't find your library files.

XP or Windows 7?

Depending on your operating system there are two different ways of accomplishing this. As I only have XP and Win7 that's all I can advise on. If you have another operating system and have success in doing this please feel free to update this article with that information. There's some information for Linux users in the "Further Reading" section at the foot of this article.

Both the (simple) ways below (for XP and Win7) describe a command line method of achieving this. It just requires that you open up what looks like a old-style DOS windows (it's now called a command prompt window) and type in a few simple commands.

If this sounds like speaking Russian to you then there's a graphical tool called Link Shell Extension that does all this (and more). I haven't used it but I read the documentation that went with it and it describes the whole process simply, using pictures.

I found it OTT for a very simple, one-time set up but you may feel more comfortable using it, or want to explore this fascinating topic in more detail.

You can find the tool and the documentation right here http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html

But now, back to the simple, command-line methods of doing this.

Windows XP

(Thanks goes to Jerry Messina, Swordfish forum member, who validated this section)

First things first:

  • Create your Dropbox account and get all that working. I'm not going to describe that here.

On XP, Swordfish will have already created a set of folders in C:\Program Files\Mecanique\Swordfish. On my system it only contained sub-folders called Samples and the infamous UserLibrary.

  • Make a note of the location of the full folder path - you'll need it later. Type it into notepad or somewhere so you can copy and paste it later. It's too easy to mistype it and get it wrong.
  • Move the Swordfish folder under your Dropbox folder. It can be placed into a sub-folder of your Dropbox account (e.g. Dropbox\PIC\Swordfish)
  • Note that I said "move" and not "copy". You don't want the Swordfish folder to remain in its original location. (Back it up first).
  • Make a note of that location too in same way described above.

Now you're going to create a pseudo-folder where Swordfish expects it (the one you just moved). In XP terminology this is called a junction or symbolic link. It makes it look as though a folder is in a particular place but in reality it's just a pointer to a real folder somewhere else.

Junction.exe is a command line utility but it is very easy to use so don't panic.

  • Make sure you have the full file path of your DropBox Swordfish folder to hand
  • Make sure you have the full file path of the original Swordfish folder location
  • Fire up a Command line prompt (Start, Run)
  • Type junction "<original Swordfish folder>" "<new Dropbox Swordfish folder>"
  • Make sure you get the folder names in the right order!

Note that you'll need to place the folder names inside double quotes for this to work as you undoubtedly have spaces in those names which would cause the command to fail.

If you copy the full folder path from a text file you can then paste the name into the command line window by clicking on the top left hand window (title bar) button and choosing Edit, Paste. Makes life so much easier (and error free).

You will then see something like this appear:

 Junction v1.06 - Windows junction creator and reparse point viewer
 Copyright (C) 2000-2010 Mark Russinovich
 Sysinternals - www.sysinternals.com

 Created: C:\Program Files\Mecanique\Swordfish\UserLibrary
 Targetted at: C:\Documents and Settings\Ralph\My Documents\Dropbox\PIC programming\Swordfish\UserLibrary

Job done! If you now browse to the "original" folder location it will look as though there really is a Swordfish folder there with the contents you moved. But the reality is that it is simply a mirror of what actually exists in your specified Dropbox folder. Make a change in the UserLibrary folder and see it instantly appear in the other location.

Windows 7

(Thanks goes to RangerBob, Swordfish forum member, who told me how to do this)

Microsoft changed the way folders are used in Windows 7 so the process is different.

  • Install Dropbox as mentioned for XP, above. No changes there.

Ignore any files you find in C:\ProgamData\Mecanique - these are not the ones you need to move, even though there may be a UserLibrary folder sitting there.

  • Find the original Swordfish set of user folders in C:\Users\<yourUserName>\Documents\Swordfish
  • Make a note of the name (copy/paste it into Notepad or an email or something)
  • Move the Swordfish folder (and all underlying sub-folders) to a Dropbox location of your choice
  • Ensure the original Swordfish folder has now disappeared

To create the Swordfish pseudo-folder under Windows 7 we can use the built in mklink command line utility.

  • Fire up a Command prompt - with Administrator privileges. How?
    • Click the Windows 7 "Start" button.
    • In the Search programs and files box enter cmd.exe
    • Let Windows offer you the correct file in the list
    • Make sure the program is highlighted in the list of programs
    • Press CTRL-SHIFT-ENTER to launch it with Administrator rights

You'll know if you have done it correctly because the command line (DOS) prompt will open and the title bar will be similar to "Administrator: C:\Windows\system32\cmd.exe".

If all you see in the title bar is C:\Windows\system32\cmd.exe (without the Administrator prefix) then you're not running with Administrator privileges and the next bit won't work. Instead, you'll get an "Access Denied" error message.

  • At the command prompt (the one with Administrator privileges) type:
  • mklink /D "<original Swordfish folder name>" "<New Dropbox Swordfish folder name>"
  • Make sure you get the folder names in the right order!

Put the folder names inside double quotes as otherwise spaces in the names will cause the command to fail.

You should see something similar to

 symbolic link created for C:\<original Swordfish folder> <<====>> C:\<new Dropbox Swordfish folder>

Job done! If you now browse to the "original" folder location it will look as though there really is a Swordfish folder there with the contents you moved. But the reality is that it is simply a mirror of what actually exists in your specified Dropbox folder. Make a change in the UserLibrary folder and see it instantly appear in the other location.

Further reading

If you want to know much, much more about symbolic links try reading this.