Forum > General

[SOLVED] Read file inside app bundle MacOs

(1/4) > >>

madref:
This peace of code did work perfectly on OS Monterey.

--- 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";}};} ---  ProgramDir := LeftStr (ExtractFilePath(Application.ExeName), Length(ExtractFilePath(Application.ExeName))-15);  if ProgramDir[Length(ProgramDir)] <> '/' then ProgramDir := ProgramDir + '/';  ResourceDir := ProgramDir + 'Contents/Resources/';  RapportDir := ResourceDir + 'Reports/';  UserDir := GetUserDir + 'Documents/Referee Database 5/';  LogoDir := ResourceDir + 'Logos/';  // Waar staat het bestand met de opties.  cfgFile := ResourceDir + 'Referee5_DB.xml' ;  if FileExists(cfgFile) then    begin      XMLConfig_DB.Filename := cfgFile ;      // Check version      Code := AnsiString(XMLConfig_DB.GetValue ('/DATABASE/Version/Value', ''));      k := StrToInt(Code);      v := StrToInt(Copy(Prg_Versie,1,1));      if k <> v then begin        KleurPop := Rood;        Form_Melding.Melding(mUitroep1, bOk, 'Options File is for different version. Please go to the Option Form and set all your options!!', PrgNaam);      end;  // if      RefereeDBF := AnsiString(XMLConfig_DB.GetValue ('/DATABASE/Current/Value', ''));      k := XMLConfig_DB.GetValue ('/SETUP/Color/Value', 1);      case k of        0 : KleurPop := Rood;        1 : KleurPop := Oranje;        2 : KleurPop := Blauw;        3 : KleurPop := Groen;        4 : KleurPop := Paars;        5 : KleurPop := Geel;        6 : KleurPop := Zwart;      end;  // case k      Shirt_Style := XMLConfig_DB.GetValue ('/SETUP/Style/Value', 1);      Cipher:= TDCP_rc4.Create(Self);      Cipher.InitStr(cfgFile,TDCP_sha256);         // initialize the cipher with a hash of the passphrase      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_MS/Value', ''));      smtpHost := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_MP/Value', ''));      smtpPort := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_UN/Value', ''));      smtpUser := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_UP/Value', ''));      smtpPassword := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_NM/Value', ''));      SenderName := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_NE/Value', ''));      SenderEMail := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_TI/Value', ''));      SenderTitel := MyDecryption(Code);      Code := AnsiString(XMLConfig_DB.GetValue ('/SETUP/Base_RP/Value', ''));      SenderRapportEmail := MyDecryption(Code);      Cipher.Burn;      Cipher.Free;    end  else begin    KleurPop := Rood;  // Standaard keuze    smtpHost := '';    smtpPort := '';    smtpUser := '';    smtpPassword := '';    SenderName := '';    SenderEMail := '';    SenderTitel := '';    SenderRapportEmail := '';    // Maak een XML-file aan.      AssignFile(F,cfgFile);    try      Rewrite(F);      Writeln(F,'<?xml version="1.0" encoding="utf-8"?>');      Writeln(F,'<REFEREE_5>');      Writeln(F,'  <DATABASE>');      Writeln(F,'  </DATABASE>');      Writeln(F,'  <SETUP>');      Writeln(F,'    <Color Value="0"/>');      Writeln(F,'  </SETUP>');      Writeln(F,'</REFEREE_5>');    finally      CloseFile(F);    end;  // try  end;  // if 

But after upgrading to OS Sonoma this is a total disaster.


How can I read a file inside my app bundle in OS Sonoma

jamie:
your code can be clean up a little to make it easier to debug.

The first two lines you have can be replaced with the

ExtractFilePath(Application......);

That will remove everything to the right up to the last "/" and will include the "/" too.

madref:
yes... but that still leaves the problem

dbannon:
Without seeing the bundle or the errors generated, not a lot anyone can do here I suspect.

Davo

jamie:

--- Quote from: madref on May 12, 2024, 02:33:45 am ---yes... but that still leaves the problem

--- End quote ---

Problem being what? I noticed you are subtracting 15 chars from the end. What I suggested will remove that.

Are you sure the path length hasn't changed and your -15 is wrong? which is why I suggested cleaning up that code and let the function take care of that part.

Navigation

[0] Message Index

[#] Next page

Go to full version