From add0db0bee8fc642e7efb9763d1914cc07b6e9d9 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Thu, 7 Jan 2016 05:22:03 +0000 Subject: [PATCH] iphonelazext: changed update Xcode project. Only create info.plist, if file doesn't exist, reuse, if existing info.plist git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4417 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/iphonelazext/ideext.pas | 1 + components/iphonelazext/iphonebundle.pas | 56 ++++- components/iphonelazext/plistfile.pas | 199 +++++++++++++++--- .../iphonelazext/tests/plist/plistread.lpr | 31 ++- components/iphonelazext/xcodeutils.pas | 10 +- 5 files changed, 253 insertions(+), 44 deletions(-) diff --git a/components/iphonelazext/ideext.pas b/components/iphonelazext/ideext.pas index f4c8f9b45..fb23a0872 100644 --- a/components/iphonelazext/ideext.pas +++ b/components/iphonelazext/ideext.pas @@ -19,6 +19,7 @@ unit ideext; interface uses + {$ifdef darwin}BaseUnix, Unix,{$endif} process, Classes, SysUtils, contnrs, Graphics, Controls, Forms, Dialogs, LazFileUtils, diff --git a/components/iphonelazext/iphonebundle.pas b/components/iphonelazext/iphonebundle.pas index 73f857d71..db05509bf 100644 --- a/components/iphonelazext/iphonebundle.pas +++ b/components/iphonelazext/iphonebundle.pas @@ -19,7 +19,7 @@ unit iPhoneBundle; interface uses - Classes, SysUtils, LazFileUtils; + Classes, SysUtils, LazFileUtils, PlistFile; const platform_iPhoneSim = 'iphonesimulator'; @@ -47,6 +47,7 @@ procedure MakeSimSpaceStruct(const iPhoneSimUserPath, SpaceName, BundleName: Wid function GetBundleExeName(const BundleAppDir, ExeName: WideString): WideString; procedure WritePkgFile(const FileName: WideString); +function WriteDefInfoList_(const InfoFileName, BundleName, ExeName: WideString; const info: TiPhoneBundleInfo): Boolean; function WriteDefInfoList(const InfoFileName, BundleName, ExeName: WideString; const info: TiPhoneBundleInfo): Boolean; procedure CreateBundle(const BundleName, ExeName: WideString; const Info: TiPhoneBundleInfo; var FullBundlePath, FullExeName: WideString); @@ -198,7 +199,55 @@ begin fs.Free; end; +procedure InitDefaultPlist(pl: TPListFile); +var + arr : TPListValue; +begin + SetStr(pl, 'CFBundleDevelopmentRegion', 'English'); + SetStr(pl, 'CFBundleDisplayName', ''); + SetStr(pl, 'CFBundleExecutable', ''); + SetStr(pl, 'CFBundleIdentifier', ''); + SetStr(pl, 'CFBundleInfoDictionaryVersion', '6.0'); + SetStr(pl, 'CFBundleName', ''); + SetStr(pl, 'CFBundlePackageType', 'APPL'); + SetStr(pl, 'CFBundleSignature', '????'); + SetArr(pl, 'CFBundleSupportedPlatforms'); + SetStr(pl, 'CFBundleVersion', '1.0'); + SetStr(pl, 'DTPlatformName', ''); + SetStr(pl, 'DTSDKName', ''); + SetBool(pl, 'LSRequiresIPhoneOS', true); + arr:=SetArr(pl, 'UISupportedInterfaceOrientations'); + AddStr(arr, 'UIInterfaceOrientationPortrait'); + AddStr(arr, 'UIInterfaceOrientationLandscapeLeft'); +end; + function WriteDefInfoList(const InfoFileName, BundleName, ExeName: WideString; const info: TiPhoneBundleInfo): Boolean; +var + pl : TPListFile; + arr : TPListValue; +begin + pl := TPListFile.Create; + try + if not FileExists(InfoFileName) then begin + InitDefaultPlist(pl); + end else + LoadFromFile(InfoFileName, pl); + SetStr(pl, 'CFBundleDisplayName', info.DisplayName); + SetStr(pl, 'CFBundleExecutable', ExeName); + SetStr(pl, 'CFBundleIdentifier', info.AppID); + SetStr(pl, 'CFBundleName', BundleName); + arr:=SetArr(pl, 'CFBundleSupportedPlatforms'); + SetStr(arr, 0, info.iPlatform); + SetStr(pl, 'DTPlatformName', info.iPlatform); + SetStr(pl, 'DTSDKName', info.SDKVersion); + + SaveToXMLFile(pl, InfoFileName); + finally + pl.Free; + end; +end; + +function WriteDefInfoList_(const InfoFileName, BundleName, ExeName: WideString; const info: TiPhoneBundleInfo): Boolean; const BundleFormat : AnsiString = ''#10+ @@ -219,6 +268,11 @@ const ' DTPlatformName'#10+ ' %s'#10+ {platform} ' DTSDKName'#10+ ' %s'#10+ {sdk version} ' LSRequiresIPhoneOS'#10+ ' '#10+ + ' UISupportedInterfaceOrientations'#10+ + ' '#10+ + ' UIInterfaceOrientationPortrait'#10+ + ' UIInterfaceOrientationLandscapeLeft'#10+ + ' '#10+ ''#10+ ''; diff --git a/components/iphonelazext/plistfile.pas b/components/iphonelazext/plistfile.pas index aee41d853..4deef74da 100644 --- a/components/iphonelazext/plistfile.pas +++ b/components/iphonelazext/plistfile.pas @@ -19,7 +19,7 @@ unit PlistFile; interface uses - Classes, SysUtils, DOM, XMLRead; + Classes, SysUtils, DOM, XMLRead{$ifdef darwin},process{$endif}; type TPlistType = (ltString, ltArray, ltDict, ltData, ltDate, ltBoolean, ltNumber); @@ -29,6 +29,8 @@ type TPListValue = class(TObject) private fType : TPlistType; + protected + function GetValueIndex(const aname: string; force: Boolean): Integer; public str : WideString; binary : array of byte; @@ -42,21 +44,20 @@ type constructor Create(AType: TPlistType); destructor Destroy; override; function AddValue: Integer; - property ValueType: TPListType read fType; function FindValue(const nm: string): Integer; + procedure Delete(idx: Integer); + procedure Clear; + property ValueType: TPListType read fType; end; { TPListFile } TPListFile = class(TObject) protected - function GetValueIdx(const aname: string; force: Boolean): Integer; public root : TPListValue; constructor Create; destructor Destroy; override; - function GetStrValue(const valname: string): string; - procedure SetStrValue(const AName: string; const AValue: WideString; AValType: TPlistType = ltString); end; function LoadFromXML(const fn: string; plist: TPListFile): Boolean; overload; @@ -68,9 +69,47 @@ procedure DebugPlistFile(const fl: TPListFile); function LoadFromFile(const fn: string; plist: TPListFile): Boolean; +function GetStr(dict: TPListValue; const AName: string): string; overload; +function GetStr(pl: TPListFile; const AName: string): string; overload; inline; + +procedure SetStr(vl: TPListValue; const AValue: WideString); overload; +procedure SetStr(dict: TPListValue; const AName: string; const AValue: WideString); overload; +procedure SetStr(arr: TPListValue; idx: Integer; const AValue: WideString); overload; +procedure SetStr(pl: TPListFile; const AName: string; const AValue: WideString); overload; inline; + +procedure SetBool(dict: TPListvalue; const AName: string; AValue: Boolean); overload; +procedure SetBool(pl: TPListFile; const AName: string; AValue: Boolean); overload; inline; + +function AddItem(vl: TPListValue; const name: string; tp: TPListType = ltString): Integer; overload; +function AddItem(vl: TPListValue; tp: TPListType = ltString ): Integer; overload; +procedure AddStr(arr: TPListValue; const AValue: WideString); + +function SetArr(vl: TPListValue; const AName: string): TPListValue; overload; +function SetArr(pl: TPListFile; const AName: string): TPListValue; overload; inline; implementation +function AddItem(vl: TPListValue; const name: string; tp: TPListType = ltString): Integer; overload; +begin + Result:=AddItem(vl, tp); + if vl.ValueType=ltDict then + vl.names[Result]:=name; +end; + +function AddItem(vl: TPListValue; tp: TPListType = ltString ): Integer; overload; +var + idx : integer; +begin + if not Assigned(vl) then begin + Result:=-1; + Exit; + end; + idx:=vl.AddValue; + if not Assigned(vl.items[idx]) then + vl.items[idx]:=TPListValue.Create(tp); + Result:=idx; +end; + procedure DebugValue(kv: TPListValue; const prefix: string ); var i : integer; @@ -120,7 +159,7 @@ begin else begin {$ifdef darwin} // the utility is not available anywhere else but OSX - if not ExecCmdLineStdOut('plutil -convert xml1 -o - "'+fn+'"', xs, err) then begin + if not RunCommand('plutil', ['-convert','xml1','-o' ,'-', fn], xs) then begin Result:=false; Exit; end; @@ -184,12 +223,16 @@ begin if (Result='') and (b<>'') then Result:=b else begin - if jltDict) then begin + if not Assigned(dict) or (dict.ValueType<>ltDict) then begin Result:=''; Exit; end; - for i:=0 to root.count-1 do - if root.names[i]=valname then begin - Result:=UTF8Encode(root.items[i].str); + for i:=0 to dict.count-1 do + if dict.names[i]=AName then begin + Result:=UTF8Encode(dict.items[i].str); Exit; end; Result:=''; - end; -procedure TPListFile.SetStrValue(const AName: string; const AValue: WideString; AValType: TPlistType); +procedure SetStr(vl: TPListValue; const AValue: WideString); +begin + if not Assigned(vl) then Exit; + vl.str:=AValue; + vl.fType:=ltString; +end; + +procedure SetStr(dict: TPListValue; const AName: string; const AValue: WideString); var idx: integer; begin - idx:=GetValueIdx(aname, true); - writeln('idx= ', idx,' ',length(root.items),' ',root.count,' ',Assigned(root.items[idx])); - root.items[idx].str:=avalue; - writeln('222'); - root.items[idx].fType:=AValType; - writeln('333'); + idx:=dict.GetValueIndex(AName, true); + SetStr(dict.items[idx], Avalue); +end; + +procedure SetBool(dict: TPListvalue; const AName: string; AValue: Boolean); overload; +var + idx: integer; +begin + idx:=dict.GetValueIndex(AName, true); + dict.items[idx].bool:=AValue; + dict.items[idx].fType:=ltBoolean; +end; + +procedure SetStr(pl: TPListFile; const AName: string; const AValue: WideString); overload; inline; +begin + SetStr(pl.root, AName, AValue); +end; + +procedure SetBool(pl: TPListFile; const AName: string; AValue: Boolean); overload; inline; +begin + SetBool(pl.root, AName, AValue); +end; + +procedure SetStr(arr: TPListValue; idx: Integer; const AValue: WideString); overload; +begin + if not Assigned(arr) or (arr.ValueType<>ltArray) or (idx<0) or (idx>arr.count) then Exit; + if idx=arr.count then + AddStr(arr, Avalue) + else begin + if not Assigned(arr.items[idx]) then arr.items[idx]:=TPListValue.Create(ltString); + SetStr(arr.items[idx], AValue); + end; +end; + +procedure AddStr(arr: TPListValue; const AValue: WideString); +var + idx: integer; +begin + idx:=AddItem(arr, ltString); + arr.items[idx].str:=AValue; +end; + +function GetStr(pl: TPListFile; const AName: string): string; overload; inline; +begin + Result:=GetStr(pl.root, AName); +end; + +function SetArr(vl: TPListValue; const AName: string): TPListValue; overload; +var + idx: integer; +begin + idx:=vl.GetValueIndex(AName, true); + Result:=vl.items[idx]; + Result.fType:=ltArray; +end; + +function SetArr(pl: TPListFile; const AName: string): TPListValue; overload; inline; +begin + Result := SetArr(pl.root, AName); end; { TPListValue } @@ -426,12 +528,8 @@ begin end; destructor TPListValue.Destroy; -var - i : integer; begin - for i:=0 to length(items)-1 do - if Assigned(items[i]) then - items[i].Free; + Clear; inherited Destroy; end; @@ -462,5 +560,36 @@ begin Result:=-1; end; +procedure TPListValue.Delete(idx: Integer); +var + i : integer; +begin + if (idx<0) or (idx>=count) then Exit; + items[idx].Free; + if ValueType=ltDict then names[idx]:=''; + + if idx