Recent

Author Topic: [SOLVED] Portable Lazarus installation  (Read 13258 times)

JoeJoeTV

  • Jr. Member
  • **
  • Posts: 65
  • Hobbyist Programmer
    • Useless Website
[SOLVED] 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?
« Last Edit: September 24, 2019, 05:59:09 pm by JoeJoeTV »
Lazarus 2.2.4 / FPC 3.2.2 / 64bit / Linux Mint 21.1 Cinnamon
https://github.com/JoeJoeTV

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: Portable Lazarus installation
« Reply #1 on: August 17, 2019, 03:09:10 pm »
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

JoeJoeTV

  • Jr. Member
  • **
  • Posts: 65
  • Hobbyist Programmer
    • Useless Website
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.2.4 / FPC 3.2.2 / 64bit / Linux Mint 21.1 Cinnamon
https://github.com/JoeJoeTV

ASerge

  • Hero Member
  • *****
  • Posts: 2212
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

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
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

  • Jr. Member
  • **
  • Posts: 65
  • Hobbyist Programmer
    • Useless Website
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.2.4 / FPC 3.2.2 / 64bit / Linux Mint 21.1 Cinnamon
https://github.com/JoeJoeTV

JoeJoeTV

  • Jr. Member
  • **
  • Posts: 65
  • Hobbyist Programmer
    • Useless Website
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.2.4 / FPC 3.2.2 / 64bit / Linux Mint 21.1 Cinnamon
https://github.com/JoeJoeTV

wp

  • Hero Member
  • *****
  • Posts: 11830
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 »

JoeJoeTV

  • Jr. Member
  • **
  • Posts: 65
  • Hobbyist Programmer
    • Useless Website
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.2.4 / FPC 3.2.2 / 64bit / Linux Mint 21.1 Cinnamon
https://github.com/JoeJoeTV

Mike_HDF

  • New Member
  • *
  • Posts: 15
Re: [SOLVED] Portable Lazarus installation
« Reply #9 on: February 10, 2021, 09:10:47 am »
Great solution, JoeJoeTV.

Just want to say there's a problem if you have some packages added from the online repository, the path could point to the Windows' users folder in packagefiles.xml (they're grouped under the tag UserPkgLinks). Lazarus will popup a message saying that the package can't be found.

Here is the code I added to yours to fix it:

Code: Pascal  [Select][+][-]
  1. var
  2. //[...]
  3. j: Integer;
  4. //[...]
  5.  
  6. //After editing editoroptions.xml, for example, you can add:
  7. //Check packagesfiles.xml for downloaded packages
  8. if FileExists(lazarusDir+confPath+'packagefiles.xml') then begin
  9.   WriteLn('SUCCESS');
  10.   WriteLn('Editing Package files xml...');
  11.  
  12.   try
  13.     ReadXMLFile(XMLDoc,lazarusDir+confPath+'packagefiles.xml',[xrfAllowSpecialCharsInAttributeValue,xrfAllowSpecialCharsInComments,xrfPreserveWhiteSpace]);
  14.     nodeEnvOpt := XMLDoc.DocumentElement.FindNode('UserPkgLinks');
  15.  
  16.     if nodeEnvOpt <> Nil then begin
  17.       with nodeEnvOpt.ChildNodes do begin
  18.         for j := 0 to (Count - 1) do begin
  19.           tmpDOMNode := Item[j].FindNode('Filename');
  20.  
  21.           if tmpDOMNode <> Nil then begin
  22.             if tmpDOMNode.Attributes.GetNamedItem('Value') <> Nil then begin
  23.               tmpDOMNode.Attributes.GetNamedItem('Value').TextContent := ReplaceRegExpr('.*\\(onlinepackagemanager\\.*)',tmpDOMNode.Attributes.GetNamedItem('Value').TextContent,QuoteRegExprMetaChars(lazarusDir + confPath)+'$1',True);
  24.             end;
  25.           end;
  26.         end;
  27.       end;
  28.  
  29.       WriteLn('DONE');
  30.  
  31.       Write('Writing packagefiles.xml back to file...');
  32.       WriteXMLFile(XMLDoc,lazarusDir + confPath + 'packagefiles.xml');
  33.       WriteLn('DONE');
  34.     end;
  35.   finally
  36.     tmpDOMNode.Free;
  37.     nodeEnvOpt.Free;
  38.     XMLDoc.Free;
  39.   end;
  40. end else begin
  41.   WriteLn('FAIL');
  42.   WriteLn;
  43.   Write('Press any key to exit...');
  44.   ReadLn;
  45. end;
  46.  

Blade

  • Full Member
  • ***
  • Posts: 177
Re: [SOLVED] Portable Lazarus installation
« Reply #10 on: November 24, 2021, 12:18:48 am »
Happen to see this, and still think it's a great idea.  Particularly if this concept could be implemented on other OSes.

JoeJoeTV

  • Jr. Member
  • **
  • Posts: 65
  • Hobbyist Programmer
    • Useless Website
Re: [SOLVED] Portable Lazarus installation
« Reply #11 on: November 24, 2021, 12:25:28 am »
Great solution, JoeJoeTV.

Just want to say there's a problem if you have some packages added from the online repository, the path could point to the Windows' users folder in packagefiles.xml (they're grouped under the tag UserPkgLinks). Lazarus will popup a message saying that the package can't be found.

Here is the code I added to yours to fix it:

Code: Pascal  [Select][+][-]
  1. var
  2. //[...]
  3. j: Integer;
  4. //[...]
  5.  
  6. //After editing editoroptions.xml, for example, you can add:
  7. //Check packagesfiles.xml for downloaded packages
  8. if FileExists(lazarusDir+confPath+'packagefiles.xml') then begin
  9.   WriteLn('SUCCESS');
  10.   WriteLn('Editing Package files xml...');
  11.  
  12.   try
  13.     ReadXMLFile(XMLDoc,lazarusDir+confPath+'packagefiles.xml',[xrfAllowSpecialCharsInAttributeValue,xrfAllowSpecialCharsInComments,xrfPreserveWhiteSpace]);
  14.     nodeEnvOpt := XMLDoc.DocumentElement.FindNode('UserPkgLinks');
  15.  
  16.     if nodeEnvOpt <> Nil then begin
  17.       with nodeEnvOpt.ChildNodes do begin
  18.         for j := 0 to (Count - 1) do begin
  19.           tmpDOMNode := Item[j].FindNode('Filename');
  20.  
  21.           if tmpDOMNode <> Nil then begin
  22.             if tmpDOMNode.Attributes.GetNamedItem('Value') <> Nil then begin
  23.               tmpDOMNode.Attributes.GetNamedItem('Value').TextContent := ReplaceRegExpr('.*\\(onlinepackagemanager\\.*)',tmpDOMNode.Attributes.GetNamedItem('Value').TextContent,QuoteRegExprMetaChars(lazarusDir + confPath)+'$1',True);
  24.             end;
  25.           end;
  26.         end;
  27.       end;
  28.  
  29.       WriteLn('DONE');
  30.  
  31.       Write('Writing packagefiles.xml back to file...');
  32.       WriteXMLFile(XMLDoc,lazarusDir + confPath + 'packagefiles.xml');
  33.       WriteLn('DONE');
  34.     end;
  35.   finally
  36.     tmpDOMNode.Free;
  37.     nodeEnvOpt.Free;
  38.     XMLDoc.Free;
  39.   end;
  40. end else begin
  41.   WriteLn('FAIL');
  42.   WriteLn;
  43.   Write('Press any key to exit...');
  44.   ReadLn;
  45. end;
  46.  

Happen to see this, and still think it's a great idea.  Particularly if this concept could be implemented on other OSes.

I just saw these two answers, I must have missed the notification for the first one.

I'm glad you enjoy this little application of mine.

I'm going to look into the fix that @Mike_HDF suggested sometime, but I need to setup Lazarus on Windows again, since I mostly use Linux now.

I may also look into making a Linux version.
Lazarus 2.2.4 / FPC 3.2.2 / 64bit / Linux Mint 21.1 Cinnamon
https://github.com/JoeJoeTV

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4458
  • I like bugs.
Re: Portable Lazarus installation
« Reply #12 on: November 24, 2021, 12:41:27 am »
... I just want to get rid of that message.
One solution is to find in Lazarus startup code where it checks the version etc. and shows the dialog, then change the code to skip the dialog and always update.
Create a patch of your change and apply it to every new Lazarus version that you use in future.
Works in every OS.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018