Forum > Windows (32/64)

[SOLVED] Portable Lazarus installation

<< < (2/2)

JoeJoeTV:

--- Quote from: marcov 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=



--- End quote ---

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---@echo offecho Starting Lazarus...set "LAZDIR=%~dp0"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.

JoeJoeTV:

--- Quote from: ASerge on August 17, 2019, 04:55:44 pm ---
--- Quote from: JoeJoeTV on August 17, 2019, 02:31: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.

--- End quote ---
Assign a Persistent Drive Letter to a USB Drive

--- End quote ---

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.

wp:

--- Quote from: JoeJoeTV on August 17, 2019, 02:31: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.

Is there a way to get rid of this window?

--- End quote ---

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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  (*   <<<< THIS BLOCK IS NOT COMMENTED IN THE ORIGINAL SOURCES  end  else  if (CompareFilenames(LastCalled,CurPrgName)<>0) and     (CompareFilenames(LastCalled,AltPrgName)<>0) and     (CompareFilenames(CurPrgName,AltPrgName)<>0) // we can NOT check, if we only have the path inside the PCP  then begin    // last time the PCP was started from another lazarus exe    // => either the user forgot to pass a --pcp    //    or the user uninstalled and installed to another directory    // => warn    debugln(['Hint: (lazarus) [TMainIDE.LoadGlobalOptions]']);    debugln(['Hint: (lazarus) LastCalled="',LastCalled,'"']);    debugln(['Hint: (lazarus) CurPrgName="',CurPrgName,'"']);    debugln(['Hint: (lazarus) AltPrgName="',AltPrgName,'"']);    MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,        SimpleFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,            [LineEnding, GetSecondConfDirWarning, ChompPathDelim(PCP),             EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),        mtWarning, [mrOK, lisUpdateInfo,                    mrIgnore,                    mrAbort]);     case MsgResult of      mrOk: begin          EnvironmentOptions.LastCalledByLazarusFullPath := CurPrgName;          SaveEnvironment(False);        end;      mrIgnore: ;      else        begin          Application.Terminate;          exit;        end;*)  end;  // KEEP THE FINAL END 
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  end  else  if (CompareFilenames(LastCalled,CurPrgName)<>0) and     (CompareFilenames(LastCalled,AltPrgName)<>0) and     (CompareFilenames(CurPrgName,AltPrgName)<>0) // we can NOT check, if we only have the path inside the PCP  then begin(*    // last time the PCP was started from another lazarus exe    // => either the user forgot to pass a --pcp    //    or the user uninstalled and installed to another directory    // => warn    debugln(['Hint: (lazarus) [TMainIDE.LoadGlobalOptions]']);    debugln(['Hint: (lazarus) LastCalled="',LastCalled,'"']);    debugln(['Hint: (lazarus) CurPrgName="',CurPrgName,'"']);    debugln(['Hint: (lazarus) AltPrgName="',AltPrgName,'"']);    MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,        SimpleFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,            [LineEnding, GetSecondConfDirWarning, ChompPathDelim(PCP),             EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),        mtWarning, [mrOK, lisUpdateInfo,                    mrIgnore,                    mrAbort]);     case MsgResult of      mrOk: begin*)          EnvironmentOptions.LastCalledByLazarusFullPath := CurPrgName;          SaveEnvironment(False);(*        end;      mrIgnore: ;      else        begin          Application.Terminate;          exit;        end;    end;*)  end;
If it still does not work undo your changes in the file and recompile the IDE again.

JoeJoeTV:
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

Mike_HDF:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var//[...]j: Integer;//[...] //After editing editoroptions.xml, for example, you can add://Check packagesfiles.xml for downloaded packagesif FileExists(lazarusDir+confPath+'packagefiles.xml') then begin  WriteLn('SUCCESS');  WriteLn('Editing Package files xml...');   try    ReadXMLFile(XMLDoc,lazarusDir+confPath+'packagefiles.xml',[xrfAllowSpecialCharsInAttributeValue,xrfAllowSpecialCharsInComments,xrfPreserveWhiteSpace]);    nodeEnvOpt := XMLDoc.DocumentElement.FindNode('UserPkgLinks');     if nodeEnvOpt <> Nil then begin      with nodeEnvOpt.ChildNodes do begin        for j := 0 to (Count - 1) do begin          tmpDOMNode := Item[j].FindNode('Filename');           if tmpDOMNode <> Nil then begin            if tmpDOMNode.Attributes.GetNamedItem('Value') <> Nil then begin              tmpDOMNode.Attributes.GetNamedItem('Value').TextContent := ReplaceRegExpr('.*\\(onlinepackagemanager\\.*)',tmpDOMNode.Attributes.GetNamedItem('Value').TextContent,QuoteRegExprMetaChars(lazarusDir + confPath)+'$1',True);            end;          end;        end;      end;       WriteLn('DONE');       Write('Writing packagefiles.xml back to file...');      WriteXMLFile(XMLDoc,lazarusDir + confPath + 'packagefiles.xml');      WriteLn('DONE');    end;  finally    tmpDOMNode.Free;    nodeEnvOpt.Free;    XMLDoc.Free;  end;end else begin  WriteLn('FAIL');  WriteLn;  Write('Press any key to exit...');  ReadLn;end; 

Navigation

[0] Message Index

[*] Previous page

Go to full version