Author Topic: How to make CodeBlocks mobile.  (Read 27047 times)

Boreas

  • Guest
How to make CodeBlocks mobile.
« on: October 15, 2007, 04:24:42 am »
I would like to put CodeBlocks on my usb drive so I can take it to any computer and do my work. It was easy with DevC++, but here I cant find the setting. Where can I change the setting where it stores its configuration files? Right now it puts it in my Windows profile and I would rather have it be located in the same directory as my program so new config files wont be generated into each unique computer I visit. Thanks.

mariocup

  • Guest
Re: How to make CodeBlocks mobile.
« Reply #1 on: October 15, 2007, 08:38:35 am »
Hi Boreas,

just have a look at http://codeblocks.org/manual.shtml. This describes where to put the relevant configuration files. So if you put the default.conf in the same dir as codeblocks.exe then this configuration file will be used, but you have to ensure write access.

Offline zac

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: How to make CodeBlocks mobile.
« Reply #2 on: October 16, 2007, 02:42:50 am »
This is not actually mobile as this way, there still be setting files in the "%SystemDrive%\Documents and Settings\user\Application Data\CodeBlocks", like codesnippets.ini, cbKeyBinder10.ini and a folder share under it, if you are running cb under Windows.

I've come across a post of setting the environment to make cb more mobile (portable) as follow.

These instructions are for the codeblocks nightly builds.  A previous post in this thread has suggested that in RC2 they use the windows registry:

http://forums.codeblocks.org/index.php/topic,4475.msg35370.html#msg35370
>There should be no reason why that should not work. The development version of Code::Blocks should be alltogether relocatable ("portable").
>For RC2/Windows, that's of course not true, since RC2 writes its configuration to the Windows registry.


For the codeblocks nightly builds:

To install:

http://wiki.codeblocks.org/index.php?title=Installing_Code::Blocks_nightly_build_on_Windows
    mingw and gdb
    download nightly
    mingwm10.dllf
    wxmsw26u_gcc_cb.dll

using 7zip to extract the .7z files, put them in the same directory, so you will have:
    bin/
    ...
    codeblocks.exe
    ...
    mingwm10.dll
    wxmsw26u_gcc_cb.dll

If the directories overlap, that is fine.  If some file is being overwritten by an older version, maybe you can keep the newer version (not recall if this happened).


You can now run "codeblocks.exe".  This so far is the usual way to run a nightly build.


However, to make it portable (runnable from a portable hard disk, usb flash drive) - to make sure it writes to a local version of the settings files - you need to copy the following "run_codeblocks.bat" (windows batch) file to this directory as well.  You can copy and paste the text below into a text file and save it somewhere.  Then after a new nightly build has been setup, you can just copy this .bat file into the same directory and make sure you run using that "run_codeblocks.bat" instead of "codeblocks.exe".  The settings files (default.conf etc.) will now be saved-to/read-from a local directory "settings\Application Data\codeblocks\".

The reason this works is that codeblocks seems to look at the windows environment variable USERPROFILE.  If you change that before you run codeblocks.exe, you can point it to a local version.  The batch file sets up the changed USERPROFILE, runs codeblock.exe, and then exits itself, while codeblocks.exe remains running.

NOTE: as a clarification, this DOES NOT change the USERPROFILE for any other program or for windows in general, but ONLY for the program spawned by "run_codeblocks.bat".  So you need not be worried about the impact of changing a windows environment variable, as that impact is confined to (only seen by) programs spawned in the batch file i.e. codeblocks.exe and any programs that codeblocks.exe spawns (compilers etc.).


Now when you run "run_codeblocks.bat", the settings files will be saved in local directory "settings/Application Data/codeblocks/" that will contain the files created/saved/read by codeblocks:
    share/
    cbKeyBinder10.ini
    codesnippets.xml
    default.conf
    ...


The file "run_codeblocks.bat" should contain:

---cut here---

rem change windows environment variable USERPROFILE to point to local directory "settings"
set USERPROFILE=%~dp0settings

rem create the directory structure (in the local directory) that codeblocks will now require
rem (now that you have pointed USERPROFILE to that directory)
mkdir %USERPROFILE%

rem windows requires use of quotes here because of space in directory name
mkdir %USERPROFILE%\"Application Data"

rem for help on START, type "START /?" in windows command window (Run "cmd.exe")
rem
rem    %~dp0    same as batch file directory
rem    %*         pass on parameters that passed to this batch file to codeblocks.exe
rem
START /D"%~dp0" codeblocks.exe %*

---cut here---




This has been tested very superficially with the recent nightly build of codeblocks.  The program opens/closes fine and the settings are saved/retreived correctly.  However I have not done anything more with this setup.

Maybe users can report how this fares for more complicated use.

Thanks.


I've tried this and it seems great. But you should not run the cmd file under Windows Explorer, otherwise, all other program settings, like IE's cookies, will also be pointed to your folder. I've put a file link of the cmd file on my desktop and running on my desktop seems no such problem.

regards,

zac

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: How to make CodeBlocks mobile.
« Reply #3 on: October 18, 2007, 10:37:53 am »
wxlearner ( http://forums.codeblocks.org/index.php?action=profile;u=4008 ) made a portable version of the nightly back in May (see http://forums.codeblocks.org/index.php/topic,5956.msg45603.html#msg45603 ) and made it available at http://armorycore.com/wxlearner/CodeBlocks-Portable-rev3977.7z , he even gave the source code so you could update it if you wanted. I have run that version (it turns out to be a quite stable nightly) on my portable USB hard disk at home and at work ever since.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How to make CodeBlocks mobile.
« Reply #4 on: October 18, 2007, 11:40:44 am »
Quote
This is not actually mobile as this way, there still be setting files in the "%SystemDrive%\Documents and Settings\user\Application Data\CodeBlocks", like codesnippets.ini, cbKeyBinder10.ini and a folder share under it, if you are running cb under Windows.
Code::Blocks *is* "mobile" (relocatable). The files you mention do not belong to Code::Blocks.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline zac

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: How to make CodeBlocks mobile.
« Reply #5 on: October 19, 2007, 09:55:22 am »
Thanks codeur,

I'll take a look at the portable version. BTW, just curious, if there is a solution here why not integrated into existing build?

regards,

zac

Offline zac

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: How to make CodeBlocks mobile.
« Reply #6 on: October 19, 2007, 10:01:18 am »
Dear Thomas,

I only download the CB nightly build and install nothing else. If the files/folders are not belonged to CB, what they belonged to?

Regards,

zac

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How to make CodeBlocks mobile.
« Reply #7 on: October 20, 2007, 04:45:42 pm »
They belong to some contrib plugins for Code::Blocks, but not to Code::Blocks.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline zac

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: How to make CodeBlocks mobile.
« Reply #8 on: October 21, 2007, 08:42:50 am »
This portable version is great. But does anyone know what needed to be modified in the nightly build to have the same effect?

Regards,

zac

Offline shajunxing

  • Multiple posting newcomer
  • *
  • Posts: 25
  • Sorry for my poor English ;)
Re: How to make CodeBlocks mobile.
« Reply #9 on: October 31, 2007, 12:04:30 pm »
I've made my C::B perfectly mobile. First, install C::B and run once and you'll find configuration files in your profile folder, for example "c:\documents and settings\administrator\...\codeblocks". Copy all these files into C::B folder. Second, copy your compiler and linker and others into C::B folder. I kept each compiler in a specified folder and in each of these folder I made the structure "bin" "include" "lib". Open C::B and open "Compiler and Debugger settings", in the "search directories" tab, you can use "$(codeblocks)" instead of absolute C::B path, my setting is:

Compiler - $(codeblocks)\mingw\include
Linker - $(codeblocks)\mingw\lib

You can also use "$(codeblocks)" in your help system the same way. I copyed some help files from C++Builder and it works perfectly. Enjoy it :P