hedgewars/uPhysFSLayer.pas
branchqmlfrontend
changeset 10424 4be6cd55f1cf
parent 10129 cd2a64a1f4aa
child 10434 1614b13ad35e
equal deleted inserted replaced
10422:4cf23d4c7624 10424:4be6cd55f1cf
    11 {$IFNDEF WIN32}
    11 {$IFNDEF WIN32}
    12     {$linklib physfs}
    12     {$linklib physfs}
    13     {$linklib physlayer}
    13     {$linklib physlayer}
    14 {$ENDIF}
    14 {$ENDIF}
    15 
    15 
    16 procedure initModule;
    16 procedure initModule(localPrefix, userPrefix: PChar);
    17 procedure freeModule;
    17 procedure freeModule;
    18 
    18 
    19 type PFSFile = pointer;
    19 type PFSFile = pointer;
    20 
    20 
    21 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    21 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
   136 end;
   136 end;
   137 
   137 
   138 procedure pfsMount(path: ansistring; mountpoint: PChar);
   138 procedure pfsMount(path: ansistring; mountpoint: PChar);
   139 begin
   139 begin
   140     if PHYSFS_mount(PChar(path), mountpoint, false) then
   140     if PHYSFS_mount(PChar(path), mountpoint, false) then
   141         AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : ok')
   141         //AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : ok')
   142     else
   142     else
   143         AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
   143         //AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
   144 end;
   144 end;
   145 
   145 
   146 procedure pfsMountAtRoot(path: ansistring);
   146 procedure pfsMountAtRoot(path: ansistring);
   147 begin
   147 begin
   148     pfsMount(path, PChar(_S'/'));
   148     pfsMount(path, PChar(_S'/'));
   149 end;
   149 end;
   150 
   150 
   151 procedure initModule;
   151 procedure initModule(localPrefix, userPrefix: PChar);
   152 var i: LongInt;
   152 var i: LongInt;
   153     cPhysfsId: shortstring;
   153     cPhysfsId: shortstring;
   154     fp: PChar;
   154     fp: PChar;
   155 begin
   155 begin
   156 {$IFDEF HWLIBRARY}
       
   157     //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
   156     //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
   158     cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars';
   157     cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars';
   159 {$ELSE}
       
   160     cPhysfsId:= ParamStr(0);
       
   161 {$ENDIF}
       
   162 
   158 
   163     i:= PHYSFS_init(Str2PChar(cPhysfsId));
   159     i:= PHYSFS_init(Str2PChar(cPhysfsId));
   164     AddFileLog('[PhysFS] init: ' + inttostr(i));
   160     //AddFileLog('[PhysFS] init: ' + inttostr(i));
   165 
   161 
   166     // mount system fonts paths first
   162     // mount system fonts paths first
   167     for i:= low(cFontsPaths) to high(cFontsPaths) do
   163     for i:= low(cFontsPaths) to high(cFontsPaths) do
   168         begin
   164         begin
   169             fp := cFontsPaths[i];
   165             fp := cFontsPaths[i];
   170             if fp <> nil then
   166             if fp <> nil then
   171                 pfsMount(ansistring(fp), PChar('/Fonts'));
   167                 pfsMount(ansistring(fp), PChar('/Fonts'));
   172         end;
   168         end;
   173 
   169 
   174     pfsMountAtRoot(PathPrefix);
   170     pfsMountAtRoot(localPrefix);
   175     pfsMountAtRoot(UserPathPrefix + ansistring('/Data'));
   171     pfsMountAtRoot(userPrefix + ansistring('/Data'));
   176 
   172 
   177     hedgewarsMountPackages;
   173     hedgewarsMountPackages;
   178 
   174 
   179     // need access to teams and frontend configs (for bindings)
   175     // need access to teams and frontend configs (for bindings)
   180     pfsMountAtRoot(UserPathPrefix);
   176     pfsMountAtRoot(userPrefix);
   181 
   177 
   182     {$IFNDEF PAS2C}
   178     {$IFNDEF PAS2C}
   183     if cTestLua then
   179     if cTestLua then
   184         begin
   180         begin
   185             pfsMountAtRoot(ExtractFileDir(cScriptName));
   181             pfsMountAtRoot(ExtractFileDir(cScriptName));