Recent

Author Topic: Portable Lazarus installation  (Read 450 times)

JoeJoeTV

  • New Member
  • *
  • Posts: 31
Portable Lazarus installation
« on: August 17, 2019, 02:31:04 pm »
I wanted to use Lazarus on a portable USB stick, so I searched on the forums, etc.

The soultion I now hae is that I have a batch script that sets a environment variable to the lazarus directory and use this in every config file(fpc.cfg,command line for lazarus main dir and config dir, etc.).

This works perfectly, althought there are a few quirks.

Every time the drive letter changes and I start lazarus from the usb I get the windows(see attachment) that the config has changed and I have to click ignore every time.

Is there a way to get rid of this window?
Lazarus 2.0.4 / FPC 3.0.4 / 32+64bit / Windows 10

nouzi

  • Full Member
  • ***
  • Posts: 130
Re: Portable Lazarus installation
« Reply #1 on: August 17, 2019, 03:09:10 pm »
my english is  bad
Lazarus 2.0 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : windows 7 64bit

JoeJoeTV

  • New Member
  • *
  • Posts: 31
Re: Portable Lazarus installation
« Reply #2 on: August 17, 2019, 03:44:10 pm »
Thanks for replying, but the portablelazarus.exe only works for drive K: AFAIK.
Also my script works, I just want to get rid of the message.
Lazarus 2.0.4 / FPC 3.0.4 / 32+64bit / Windows 10

ASerge

  • Hero Member
  • *****
  • Posts: 1388
Re: Portable Lazarus installation
« Reply #3 on: August 17, 2019, 04:55:44 pm »
Every time the drive letter changes and I start lazarus from the usb I get the windows(see attachment) that the config has changed and I have to click ignore every time.
Assign a Persistent Drive Letter to a USB Drive

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7350
Re: Portable Lazarus installation
« Reply #4 on: August 17, 2019, 05:10:37 pm »
I did a try a long time ago too, I used this batchfile.

The idea is to make as many paths inside the IDE relative to lazarusdir, and then pass the lazarus.exe location to startlazarus using --lazarusdir and --pcp=


JoeJoeTV

  • New Member
  • *
  • Posts: 31
Re: Portable Lazarus installation
« Reply #5 on: August 17, 2019, 06:24:42 pm »
I did a try a long time ago too, I used this batchfile.

The idea is to make as many paths inside the IDE relative to lazarusdir, and then pass the lazarus.exe location to startlazarus using --lazarusdir and --pcp=



Well yeah, I did this and it's working.
I also have a batch file which sets a environment variable(for fpc.cfg) and starts startlazarus.exe with the lazarus dir set to the path of the batch script and the config folder a folder in there.
But the problem I have is that lazarus saves the last path in the config and when the current path of the config is not the same as the last one it will show the message, so I want to get rid of that.
A method would be, making a "launcher" in Lazarus, which I now started trying.

My Plan is modifying the environmentoptions.xml in the config directory and remove the <History> tags, but I don't know how to read xml files with Lazarus without a gui.

EDIT: Here's the batch file I used:
Code: Text  [Select]
  1. @echo off
  2. echo Starting Lazarus...
  3. set "LAZDIR=%~dp0"
  4. start "" "%LAZDIR%startlazarus.exe" --lazarusdir="%LAZDIR%" --pcp="%LAZDIR%LazConfig" --scp="%LAZDIR%" --skip-last-project --nsc

EDIT 2: I used the environment variable in fpc.cfg to replace the absolute path and I used LazarusDir everywhere I could in config files.
« Last Edit: August 17, 2019, 06:27:24 pm by JoeJoeTV »
Lazarus 2.0.4 / FPC 3.0.4 / 32+64bit / Windows 10

JoeJoeTV

  • New Member
  • *
  • Posts: 31
Re: Portable Lazarus installation
« Reply #6 on: August 17, 2019, 06:29:04 pm »
Every time the drive letter changes and I start lazarus from the usb I get the windows(see attachment) that the config has changed and I have to click ignore every time.
Assign a Persistent Drive Letter to a USB Drive

That won't work on other machines that have that drive letter already assigned and besides it works already, I just want to get rid of that message.
Lazarus 2.0.4 / FPC 3.0.4 / 32+64bit / Windows 10

wp

  • Hero Member
  • *****
  • Posts: 6134
Re: Portable Lazarus installation
« Reply #7 on: August 17, 2019, 06:54:22 pm »
Every time the drive letter changes and I start lazarus from the usb I get the windows(see attachment) that the config has changed and I have to click ignore every time.

Is there a way to get rid of this window?

I don't think so. Well, a brute force comes to my mind: Open unit "ide\main.pp", go to line 1270 (or so), comment the entire, following "if" block and rebuild the IDE - this blocks does the filename check and displays the message box:

Code: Pascal  [Select]
  1.   (*   <<<< THIS BLOCK IS NOT COMMENTED IN THE ORIGINAL SOURCES
  2.   end
  3.   else
  4.   if (CompareFilenames(LastCalled,CurPrgName)<>0) and
  5.      (CompareFilenames(LastCalled,AltPrgName)<>0) and
  6.      (CompareFilenames(CurPrgName,AltPrgName)<>0) // we can NOT check, if we only have the path inside the PCP
  7.   then begin
  8.     // last time the PCP was started from another lazarus exe
  9.     // => either the user forgot to pass a --pcp
  10.     //    or the user uninstalled and installed to another directory
  11.     // => warn
  12.     debugln(['Hint: (lazarus) [TMainIDE.LoadGlobalOptions]']);
  13.     debugln(['Hint: (lazarus) LastCalled="',LastCalled,'"']);
  14.     debugln(['Hint: (lazarus) CurPrgName="',CurPrgName,'"']);
  15.     debugln(['Hint: (lazarus) AltPrgName="',AltPrgName,'"']);
  16.     MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,
  17.         SimpleFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,
  18.             [LineEnding, GetSecondConfDirWarning, ChompPathDelim(PCP),
  19.              EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),
  20.         mtWarning, [mrOK, lisUpdateInfo,
  21.                     mrIgnore,
  22.                     mrAbort]);
  23.  
  24.     case MsgResult of
  25.       mrOk: begin
  26.           EnvironmentOptions.LastCalledByLazarusFullPath := CurPrgName;
  27.           SaveEnvironment(False);
  28.         end;
  29.       mrIgnore: ;
  30.       else
  31.         begin
  32.           Application.Terminate;
  33.           exit;
  34.         end;
  35. *)
  36.   end;  // KEEP THE FINAL END
  37.  

But be warned: Changes in the new paths are not written to the config files any more. You must absolutely be sure that the environment setting is respected by all tools involved (which I doubt).

Or, if it does not work, you could keep the two lines of the mrOK branch and force writing the environment in any case, it is as if you had pressed the OK button - I think this is not harmful even if not required, just takes a short time:

Code: Pascal  [Select]
  1.   end
  2.   else
  3.   if (CompareFilenames(LastCalled,CurPrgName)<>0) and
  4.      (CompareFilenames(LastCalled,AltPrgName)<>0) and
  5.      (CompareFilenames(CurPrgName,AltPrgName)<>0) // we can NOT check, if we only have the path inside the PCP
  6.   then begin
  7. (*
  8.     // last time the PCP was started from another lazarus exe
  9.     // => either the user forgot to pass a --pcp
  10.     //    or the user uninstalled and installed to another directory
  11.     // => warn
  12.     debugln(['Hint: (lazarus) [TMainIDE.LoadGlobalOptions]']);
  13.     debugln(['Hint: (lazarus) LastCalled="',LastCalled,'"']);
  14.     debugln(['Hint: (lazarus) CurPrgName="',CurPrgName,'"']);
  15.     debugln(['Hint: (lazarus) AltPrgName="',AltPrgName,'"']);
  16.     MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,
  17.         SimpleFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,
  18.             [LineEnding, GetSecondConfDirWarning, ChompPathDelim(PCP),
  19.              EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),
  20.         mtWarning, [mrOK, lisUpdateInfo,
  21.                     mrIgnore,
  22.                     mrAbort]);
  23.  
  24.     case MsgResult of
  25.       mrOk: begin
  26. *)
  27.           EnvironmentOptions.LastCalledByLazarusFullPath := CurPrgName;
  28.           SaveEnvironment(False);
  29. (*        end;
  30.       mrIgnore: ;
  31.       else
  32.         begin
  33.           Application.Terminate;
  34.           exit;
  35.         end;
  36.     end;
  37. *)
  38.   end;

If it still does not work undo your changes in the file and recompile the IDE again.
« Last Edit: August 17, 2019, 07:14:42 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

JoeJoeTV

  • New Member
  • *
  • Posts: 31
Re: Portable Lazarus installation
« Reply #8 on: August 22, 2019, 10:49:11 pm »
I have now solved the problem by writing a program in lazarus to set all config paths and start lazarus.

I have made the source code public on github if anyone is interested. I works out of the box with a fresh install of lazarus in one folder but lazarus has to be started from this app.

https://github.com/JoeJoeTV/startLazarusPortable
Lazarus 2.0.4 / FPC 3.0.4 / 32+64bit / Windows 10