Commit e7baa6872c6ab4cfe4be4e93628f0345e934813a
- Diff rendering mode:
- inline
- side by side
docs/ipk-specification-v1.1.txt
(107 / 0)
|   | |||
| 1 | ===== IPK 1.1 Specification ===== | ||
| 2 | |||
| 3 | FIXME This specifications are @work! Some information might change due the development process | ||
| 4 | or might just be outdated and wrong. | ||
| 5 | |||
| 6 | ==== General ==== | ||
| 7 | |||
| 8 | === Format === | ||
| 9 | |||
| 10 | An IPK setup-package is a [[http://en.wikipedia.org/wiki/Tar_%28file_format%29 | TAR-Archive]], | ||
| 11 | containing a [[http://en.wikipedia.org/wiki/Xz | XZ-Compressed]] data and control tarball. | ||
| 12 | An IPK-Package has the file extension .ipk (= **I**nstallation **p**ac**k**age), which was choosen because it is | ||
| 13 | simple and easy to remember. Unfortunately the Opkg and Ipkg package manager for Linux cellphones uses the same extension, | ||
| 14 | (and IPK was an image-format for Nintendo® games), but because Listaller setups are targeted to Linux desktops and not to | ||
| 15 | cellphones, this should not leat to much confusion. | ||
| 16 | Most of the IPK packages are named in the following pattern: InstallAppname-version_architecture.ipk | ||
| 17 | E.g if the name of the application is "Sample" the version is "1.0" and the architecture is "i386" the package should | ||
| 18 | be named InstallSample-10_i386.ipk or Sample-10_i386.ipk | ||
| 19 | |||
| 20 | === Structure === | ||
| 21 | |||
| 22 | The IPK archive contains the following files and folders at toplevel: | ||
| 23 | |||
| 24 | ^ Name ^ Required? ^ Function ^ | ||
| 25 | | files-<id>.tar.xz | yes | Contains the files which have to be installed. The <id> indicates the profile number. | | ||
| 26 | | control.tar.xz | yes | Archive with configuration files of this package, the main config file as well as e.g. Licenses, scripts, descriptions, file-info etc. | | ||
| 27 | | _signature.asc | no | A GPG ASC signature of this package. (Only exists if the package is signed) | | ||
| 28 | |||
| 29 | |||
| 30 | Listaller will detect automatically if a package is signed and check if the signature on the IPK package is valid. | ||
| 31 | |||
| 32 | ==== The control files ==== | ||
| 33 | |||
| 34 | All files configuring the behavior of an IPK package or providing additional information about it are stored | ||
| 35 | in the //control.tar.xz// archive. | ||
| 36 | |||
| 37 | On toplevel, each control archive has to contain an //arcinfo.pin// document, describing all basic stuff of the package. | ||
| 38 | |||
| 39 | === Arcinfo.pin === | ||
| 40 | |||
| 41 | The //arcinfo.pin// file contains the same information as the definition part in an IPS-script. | ||
| 42 | The package builder has changed file paths and removed some unnecessary elements, everything else is the same. | ||
| 43 | An //arcinfo.pin// file may look like this: | ||
| 44 | <code ips> | ||
| 45 | IPK-Standard-Version: 1.0 | ||
| 46 | |||
| 47 | include:"/stuff/locale/setup-es.mo" | ||
| 48 | |||
| 49 | Type: linstall | ||
| 50 | Name: FooBar | ||
| 51 | Version: 1.0-a | ||
| 52 | License: include:"/stuff/COPYING" | ||
| 53 | Description: include:"/stuff/desc.txt" | ||
| 54 | Icon: /stuff/foobar-icon.png | ||
| 55 | SDesc: A new foo-ish bar | ||
| 56 | SDesc[de]: Einen neue foo-bar | ||
| 57 | Group: Development | ||
| 58 | Author: Foobar Project | ||
| 59 | Maintainer: Pete Foo (petefoo@example.org) | ||
| 60 | Disallow: ioNothing | ||
| 61 | Profile[0]: Standard | ||
| 62 | AppCMD: $INST/foo/foobar | ||
| 63 | Architecture: i386 | ||
| 64 | DSupport: Ubuntu,openSUSE | ||
| 65 | Dependencies: | ||
| 66 | $LIB/libc6.so | ||
| 67 | $LIB/library2.so | ||
| 68 | $LIB/libnagra.so.4 | ||
| 69 | </code> | ||
| 70 | The format of an IPS definition section is described in the IPS specifications. | ||
| 71 | The following elements are IPK-specific or have different values: | ||
| 72 | |||
| 73 | * License, Description, Wizimage, Icon: The value has changed, it points now to a file in the IPK package. / is the package root. Licenses are usually saved in /stuff | ||
| 74 | * Include commands have also changed values. | ||
| 75 | * The !-Files part is missing. | ||
| 76 | |||
| 77 | @>HERE<@ | ||
| 78 | |||
| 79 | === File information === | ||
| 80 | |||
| 81 | The information about installed files is saved in text files which are stored in the /stuff folder. | ||
| 82 | Every file has a name following the sheme: fileinfo-.id The is replaced by the profile identification number. E.g. if the identification number is 2 the associated file-info file is named fileinfo-2.id The content of the fileinfo has the following structure: | ||
| 83 | <code ips> | ||
| 84 | >Destination | ||
| 85 | Internal path to file | ||
| 86 | MD5-hash | ||
| 87 | Internal path to file | ||
| 88 | MD5-hash | ||
| 89 | ... | ||
| 90 | </code> | ||
| 91 | A fileinfo-file can look like this: (extract) | ||
| 92 | <code ips> | ||
| 93 | >$INST/Songbird | ||
| 94 | /data/Songbird/LICENSE.html | ||
| 95 | 9b5151a0cfec60dbc0c3d548cfa3e713 | ||
| 96 | /data/Songbird/README.txt | ||
| 97 | a92100275b9f71115dbe82a18af61392 | ||
| 98 | /data/Songbird/TRADEMARK.txt | ||
| 99 | c82c36a2843c9ad08c42d7170a9c12d1 | ||
| 100 | /data/Songbird/songbird | ||
| 101 | 77e7be1db488bf3c4b5e8abd52d6eb23 | ||
| 102 | /data/Songbird/application.ini | ||
| 103 | ff85febb38852501439ea623725241c0 | ||
| 104 | >$INST/Songbird/jsmodules | ||
| 105 | /data/Songbird/jsmodules/sbLibraryUtils.jsm | ||
| 106 | 418a7400354cd1176264b5ec79f29be2 | ||
| 107 | </code> |
docs/ipk-specification-v1.txt
(0 / 107)
|   | |||
| 1 | ===== IPK 1.1 Specification ===== | ||
| 2 | |||
| 3 | FIXME This specifications are @work! Some information might change due the development process | ||
| 4 | or might just be outdated and wrong. | ||
| 5 | |||
| 6 | ==== General ==== | ||
| 7 | |||
| 8 | === Format === | ||
| 9 | |||
| 10 | An IPK setup-package is a [[http://en.wikipedia.org/wiki/Tar_%28file_format%29 | TAR-Archive]], | ||
| 11 | containing a [[http://en.wikipedia.org/wiki/Xz | XZ-Compressed]] data and control tarball. | ||
| 12 | An IPK-Package has the file extension .ipk (= **I**nstallation **p**ac**k**age), which was choosen because it is | ||
| 13 | simple and easy to remember. Unfortunately the Opkg and Ipkg package manager for Linux cellphones uses the same extension, | ||
| 14 | (and IPK was an image-format for Nintendo® games), but because Listaller setups are targeted to Linux desktops and not to | ||
| 15 | cellphones, this should not leat to much confusion. | ||
| 16 | Most of the IPK packages are named in the following pattern: InstallAppname-version_architecture.ipk | ||
| 17 | E.g if the name of the application is "Sample" the version is "1.0" and the architecture is "i386" the package should | ||
| 18 | be named InstallSample-10_i386.ipk or Sample-10_i386.ipk | ||
| 19 | |||
| 20 | === Structure === | ||
| 21 | |||
| 22 | The IPK archive contains the following files and folders at toplevel: | ||
| 23 | |||
| 24 | ^ Name ^ Required? ^ Function ^ | ||
| 25 | | files-<id>.tar.xz | yes | Contains the files which have to be installed. The <id> indicates the profile number. | | ||
| 26 | | control.tar.xz | yes | Archive with configuration files of this package, the main config file as well as e.g. Licenses, scripts, descriptions, file-info etc. | | ||
| 27 | | _signature.asc | no | A GPG ASC signature of this package. (Only exists if the package is signed) | | ||
| 28 | |||
| 29 | |||
| 30 | Listaller will detect automatically if a package is signed and check if the signature on the IPK package is valid. | ||
| 31 | |||
| 32 | ==== The control files ==== | ||
| 33 | |||
| 34 | All files configuring the behavior of an IPK package or providing additional information about it are stored | ||
| 35 | in the //control.tar.xz// archive. | ||
| 36 | |||
| 37 | On toplevel, each control archive has to contain an //arcinfo.pin// document, describing all basic stuff of the package. | ||
| 38 | |||
| 39 | === Arcinfo.pin === | ||
| 40 | |||
| 41 | The //arcinfo.pin// file contains the same information as the definition part in an IPS-script. | ||
| 42 | The package builder has changed file paths and removed some unnecessary elements, everything else is the same. | ||
| 43 | An //arcinfo.pin// file may look like this: | ||
| 44 | <code ips> | ||
| 45 | IPK-Standard-Version: 1.0 | ||
| 46 | |||
| 47 | include:"/stuff/locale/setup-es.mo" | ||
| 48 | |||
| 49 | Type: linstall | ||
| 50 | Name: FooBar | ||
| 51 | Version: 1.0-a | ||
| 52 | License: include:"/stuff/COPYING" | ||
| 53 | Description: include:"/stuff/desc.txt" | ||
| 54 | Icon: /stuff/foobar-icon.png | ||
| 55 | SDesc: A new foo-ish bar | ||
| 56 | SDesc[de]: Einen neue foo-bar | ||
| 57 | Group: Development | ||
| 58 | Author: Foobar Project | ||
| 59 | Maintainer: Pete Foo (petefoo@example.org) | ||
| 60 | Disallow: ioNothing | ||
| 61 | Profile[0]: Standard | ||
| 62 | AppCMD: $INST/foo/foobar | ||
| 63 | Architecture: i386 | ||
| 64 | DSupport: Ubuntu,openSUSE | ||
| 65 | Dependencies: | ||
| 66 | $LIB/libc6.so | ||
| 67 | $LIB/library2.so | ||
| 68 | $LIB/libnagra.so.4 | ||
| 69 | </code> | ||
| 70 | The format of an IPS definition section is described in the IPS specifications. | ||
| 71 | The following elements are IPK-specific or have different values: | ||
| 72 | |||
| 73 | * License, Description, Wizimage, Icon: The value has changed, it points now to a file in the IPK package. / is the package root. Licenses are usually saved in /stuff | ||
| 74 | * Include commands have also changed values. | ||
| 75 | * The !-Files part is missing. | ||
| 76 | |||
| 77 | @>HERE<@ | ||
| 78 | |||
| 79 | === File information === | ||
| 80 | |||
| 81 | The information about installed files is saved in text files which are stored in the /stuff folder. | ||
| 82 | Every file has a name following the sheme: fileinfo-.id The is replaced by the profile identification number. E.g. if the identification number is 2 the associated file-info file is named fileinfo-2.id The content of the fileinfo has the following structure: | ||
| 83 | <code ips> | ||
| 84 | >Destination | ||
| 85 | Internal path to file | ||
| 86 | MD5-hash | ||
| 87 | Internal path to file | ||
| 88 | MD5-hash | ||
| 89 | ... | ||
| 90 | </code> | ||
| 91 | A fileinfo-file can look like this: (extract) | ||
| 92 | <code ips> | ||
| 93 | >$INST/Songbird | ||
| 94 | /data/Songbird/LICENSE.html | ||
| 95 | 9b5151a0cfec60dbc0c3d548cfa3e713 | ||
| 96 | /data/Songbird/README.txt | ||
| 97 | a92100275b9f71115dbe82a18af61392 | ||
| 98 | /data/Songbird/TRADEMARK.txt | ||
| 99 | c82c36a2843c9ad08c42d7170a9c12d1 | ||
| 100 | /data/Songbird/songbird | ||
| 101 | 77e7be1db488bf3c4b5e8abd52d6eb23 | ||
| 102 | /data/Songbird/application.ini | ||
| 103 | ff85febb38852501439ea623725241c0 | ||
| 104 | >$INST/Songbird/jsmodules | ||
| 105 | /data/Songbird/jsmodules/sbLibraryUtils.jsm | ||
| 106 | 418a7400354cd1176264b5ec79f29be2 | ||
| 107 | </code> |
lib/ipkinstall.pas
(2 / 2)
|   | |||
| 21 | 21 | interface | |
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | MD5, Distri, IPKDef, Classes, Contnrs, FTPSend, LiTypes, LiUtils, MTProcs, | ||
| 24 | MD5, Distri, IPKCDef10, Classes, Contnrs, FTPSend, LiTypes, LiUtils, MTProcs, | ||
| 25 | 25 | PkTypes, Process, RegExpr, BaseUnix, Blcksock, FileUtil, HTTPSend, IniFiles, | |
| 26 | SysUtils, DepManage, strLocale, IPKPackage, liDBusProc, PackageKit, | ||
| 26 | SysUtils, DepManage, strLocale, IPKPackage11, liDBusProc, PackageKit, | ||
| 27 | 27 | SoftwareDB, LiManageApp; | |
| 28 | 28 | ||
| 29 | 29 | type |
lib/libinstaller.lpr
(1 / 1)
|   | |||
| 20 | 20 | ||
| 21 | 21 | uses | |
| 22 | 22 | CThreads, Classes, IpkInstall, SysUtils, Controls, LiTypes, LiUtils, | |
| 23 | LiManageApp, LiUpdateApp, GLib2, softwaredb; | ||
| 23 | LiManageApp, LiUpdateApp, GLib2, SoftwareDB; | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ////////////////////////////////////////////////////////////////////////////////////// |
lib/limanageapp.pas
(1 / 1)
|   | |||
| 21 | 21 | interface | |
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | ipkdef, Classes, GetText, liTypes, liUtils, MTProcs, | ||
| 24 | IPKCDef10, Classes, GetText, liTypes, liUtils, MTProcs, | ||
| 25 | 25 | PkTypes, Process, FileUtil, IniFiles, SysUtils, strLocale, | |
| 26 | 26 | liDBusProc, PackageKit, SoftwareDB; | |
| 27 | 27 |
lib/liupdateapp.pas
(1 / 1)
|   | |||
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | 24 | Blcksock, Classes, Contnrs, FileUtil, FTPSend, HTTPSend, IniFiles, | |
| 25 | IPKDef, IPKPackage, LiUtils, LiDBusProc, LiTypes, MD5, Process, | ||
| 25 | IPKCDef10, IPKPackage11, LiUtils, LiDBusProc, LiTypes, MD5, Process, | ||
| 26 | 26 | SoftwareDB, SysUtils, StrLocale; | |
| 27 | 27 | ||
| 28 | 28 | type |
src/cmdtools/ipkbuild.pas
(2 / 2)
|   | |||
| 21 | 21 | interface | |
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | MD5, IPKDef, Classes, GPGSign, liTypes, | ||
| 25 | liUtils, Process, RegExpr, FileUtil, SysUtils, IPKPackage, OPBitmapFormats; | ||
| 24 | MD5, IPKCDef10, Classes, GPGSign, LiTypes, | ||
| 25 | LiUtils, Process, RegExpr, FileUtil, SysUtils, IPKPackage11, OPBitmapFormats; | ||
| 26 | 26 | ||
| 27 | 27 | type | |
| 28 | 28 |
src/cmdtools/libuild.lpi
(1 / 1)
|   | |||
| 54 | 54 | <SearchPaths> | |
| 55 | 55 | <IncludeFiles Value="$(ProjOutDir)/"/> | |
| 56 | 56 | <Libraries Value="$(ProjOutDir)/"/> | |
| 57 | <OtherUnitFiles Value="../;../../opbitmap/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/nogui/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/"/> | ||
| 57 | <OtherUnitFiles Value="../;../bind/;../../opbitmap/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/nogui/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/"/> | ||
| 58 | 58 | <UnitOutputDirectory Value="../../build/$(TargetCPU)-$(TargetOS)"/> | |
| 59 | 59 | <LCLWidgetType Value="nogui"/> | |
| 60 | 60 | </SearchPaths> |
src/cmdtools/libuild.lpr
(3 / 2)
|   | |||
| 55 | 55 | i: Integer; | |
| 56 | 56 | x: Boolean; | |
| 57 | 57 | pki: TPackInfo; | |
| 58 | ErrorMsg: String; | ||
| 58 | 59 | begin | |
| 59 | 60 | // quick check parameters | |
| 60 | ErrorMsg:=CheckOptions('h?b:uv',['help', 'build:', 'gen-update', 'version', 'noquietcrash', 'deb', 'rpm', 'dpack', | ||
| 61 | ErrorMsg := CheckOptions('h?b:uv',['help', 'build:', 'gen-update', 'version', 'noquietcrash', 'deb', 'rpm', 'dpack', | ||
| 61 | 62 | 'generate-button', 'sign']); | |
| 62 | if ErrorMsg<>'' then | ||
| 63 | if ErrorMsg <> '' then | ||
| 63 | 64 | begin | |
| 64 | 65 | writeLn(ErrorMsg); | |
| 65 | 66 | Terminate; |
src/cmdtools/lipa.lpr
(4 / 4)
|   | |||
| 26 | 26 | Classes, SysUtils, CustApp, | |
| 27 | 27 | Process, liUtils, LiInstaller, | |
| 28 | 28 | StrLocale, IniFiles, Distri, | |
| 29 | LiTranslator, IPKdef, GExt, | ||
| 30 | LiAppMgr, liTypes, Forms; | ||
| 29 | LiTranslator, IPKCDef10, GExt, | ||
| 30 | LiAppMgr, LiTypes, Forms; | ||
| 31 | 31 | ||
| 32 | 32 | type | |
| 33 | 33 | ||
| … | … | ||
| 134 | 134 | cnf: TIniFile; | |
| 135 | 135 | begin | |
| 136 | 136 | // quick check parameters | |
| 137 | ErrorMsg:=CheckOptions('h?b:uvs:i:',['help', 'build:', 'gen-update', 'version', 'noquietcrash', 'deb', 'rpm', 'dpack', | ||
| 137 | ErrorMsg := CheckOptions('h?b:uvs:i:',['help', 'build:', 'gen-update', 'version', 'noquietcrash', 'deb', 'rpm', 'dpack', | ||
| 138 | 138 | 'generate-button', 'sign', 'solve', 'testmode', 'install:', 'verbose', 'checkapps']); | |
| 139 | if ErrorMsg<>'' then | ||
| 139 | if ErrorMsg <> '' then | ||
| 140 | 140 | begin | |
| 141 | 141 | writeLn(ErrorMsg); | |
| 142 | 142 | Terminate; |
src/cmdtools/unibuild.pas
(1 / 1)
|   | |||
| 21 | 21 | interface | |
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | Classes, SysUtils, liUtils, ipkdef, ipkbuild, Process; | ||
| 24 | Classes, SysUtils, LiUtils, IPKCDef10, IPKBuild, Process; | ||
| 25 | 25 | ||
| 26 | 26 | function ReadInformation(fips: String): TPackInfo; | |
| 27 | 27 | procedure CreateDEB(pk: TPackInfo); |
src/frontends/applist.pas
(0 / 1)
|   | |||
| 161 | 161 | size = 48; | |
| 162 | 162 | begin | |
| 163 | 163 | Items.Add(' '); | |
| 164 | |||
| 165 | 164 | new := TAppInfoItem.Create; | |
| 166 | 165 | new.Name := ai.Name; | |
| 167 | 166 | new.Author := ai.Author; |
src/frontends/listallmgr.lpi
(1 / 1)
|   | |||
| 91 | 91 | <Libraries Value="$(ProjOutDir)/"/> | |
| 92 | 92 | <OtherUnitFiles Value="../;../bind/"/> | |
| 93 | 93 | <UnitOutputDirectory Value="../../build/$(TargetCPU)-$(TargetOS)"/> | |
| 94 | <LCLWidgetType Value="gtk2"/> | ||
| 94 | <LCLWidgetType Value="qt"/> | ||
| 95 | 95 | </SearchPaths> | |
| 96 | 96 | <CodeGeneration> | |
| 97 | 97 | <SmartLinkUnit Value="True"/> |
src/frontends/manager.pas
(3 / 3)
|   | |||
| 22 | 22 | ||
| 23 | 23 | uses | |
| 24 | 24 | Spin, Forms, Menus, LiAppMgr, Distri, AppItem, AppList, GLib2, | |
| 25 | Buttons, Classes, Dialogs, LCLType, liTypes, liUtils, Process, AboutBox, | ||
| 26 | CheckLst, ComCtrls, Controls, ExtCtrls, FileUtil, Graphics, Inifiles, StdCtrls, | ||
| 25 | Buttons, Classes, Dialogs, LCLType, LiTypes, LiUtils, Process, AboutBox, | ||
| 26 | CheckLst, ComCtrls, Controls, ExtCtrls, FileUtil, Graphics, IniFiles, StdCtrls, | ||
| 27 | 27 | SysUtils, StrLocale, Uninstall, IconLoader, LResources, PackageKit, PkTypes; | |
| 28 | 28 | ||
| 29 | 29 | type | |
| … | … | ||
| 200 | 200 | Result := true; | |
| 201 | 201 | with MnFrm do | |
| 202 | 202 | begin | |
| 203 | currAppList.ItemFromAppInfo(TAppInfo(obj^)); | ||
| 203 | currAppList.ItemFromAppInfo(obj^); | ||
| 204 | 204 | end; | |
| 205 | 205 | Application.ProcessMessages; | |
| 206 | 206 | end; |
src/ipkcdef10.pas
(1223 / 0)
|   | |||
| 1 | { Copyright (C) 2008-2010 Matthias Klumpp | ||
| 2 | |||
| 3 | Authors: | ||
| 4 | Matthias Klumpp | ||
| 5 | |||
| 6 | This unit is free software: you can redistribute it and/or modify it under | ||
| 7 | the terms of the GNU General Public License as published by the Free Software | ||
| 8 | Foundation, version 3. | ||
| 9 | |||
| 10 | This unit is distributed in the hope that it will be useful, but WITHOUT | ||
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License v3 | ||
| 15 | along with this unit. If not, see <http://www.gnu.org/licenses/>.} | ||
| 16 | //** Contains classes to process IPK control and script files (version 1.0) | ||
| 17 | unit ipkcdef10; | ||
| 18 | |||
| 19 | {$mode objfpc}{$H+} | ||
| 20 | |||
| 21 | interface | ||
| 22 | |||
| 23 | uses | ||
| 24 | Classes, GetText, liTypes, liUtils, SysUtils, FileUtil; | ||
| 25 | |||
| 26 | type | ||
| 27 | |||
| 28 | //** Basic IPK reader class | ||
| 29 | TIPKBasic = class | ||
| 30 | private | ||
| 31 | function GetValue(s: String): String; | ||
| 32 | function SearchKeyIndex(s: String; localized: Boolean = true): Integer; | ||
| 33 | function SolveInclude(s: String): String; | ||
| 34 | function translate(s: String): String; | ||
| 35 | procedure WriteEntry(k, s: String); | ||
| 36 | |||
| 37 | procedure WriteType(atype: TPkgType); | ||
| 38 | function ReadType: TPkgType; | ||
| 39 | procedure WriteName(s: String); | ||
| 40 | function ReadName: String; | ||
| 41 | procedure WriteVersion(s: String); | ||
| 42 | function ReadVersion: String; | ||
| 43 | procedure WriteIcon(s: String); | ||
| 44 | function ReadIcon: String; | ||
| 45 | procedure WriteSDesc(s: String); | ||
| 46 | function ReadSDesc: String; | ||
| 47 | procedure WriteCategory(g: AppCategory); | ||
| 48 | function ReadCategory: AppCategory; | ||
| 49 | procedure WriteAuthor(s: String); | ||
| 50 | function ReadAuthor: String; | ||
| 51 | procedure WriteMaintainer(s: String); | ||
| 52 | function ReadMaintainer: String; | ||
| 53 | procedure WriteDisallows(s: String); | ||
| 54 | function ReadDisallows: String; | ||
| 55 | procedure WriteAppCMD(s: String); | ||
| 56 | function ReadAppCMD: String; | ||
| 57 | procedure WriteArchs(s: String); | ||
| 58 | function ReadArchs: String; | ||
| 59 | procedure WritePkgName(s: String); | ||
| 60 | function ReadPkgName: String; | ||
| 61 | procedure WriteIPKName(s: String); | ||
| 62 | function ReadIPKName: String; | ||
| 63 | procedure WriteDSupport(s: String); | ||
| 64 | function ReadDSupport: String; | ||
| 65 | procedure WriteWizImage(s: String); | ||
| 66 | function ReadWizImage: String; | ||
| 67 | procedure WriteBinary(s: String); | ||
| 68 | function ReadBinary: String; | ||
| 69 | procedure WriteUSource(s: String); | ||
| 70 | function ReadUSource: String; | ||
| 71 | procedure WriteDesktopFiles(s: String); | ||
| 72 | function ReadDesktopFiles: String; | ||
| 73 | procedure WriteInTerminal(b: Boolean); | ||
| 74 | function ReadInTerminal: Boolean; | ||
| 75 | protected | ||
| 76 | text: TStringList; | ||
| 77 | FBasePath: String; | ||
| 78 | clang: String; | ||
| 79 | motrans: Boolean; | ||
| 80 | mofile: String; | ||
| 81 | procedure WriteField(Name: String; info: TStrings); | ||
| 82 | procedure ReadField(Name: String; info: TStrings); | ||
| 83 | public | ||
| 84 | constructor Create; | ||
| 85 | destructor Destroy; override; | ||
| 86 | |||
| 87 | property BasePath: String read FBasePath write FBasePath; | ||
| 88 | property SType: TPkgType read ReadType write WriteType; | ||
| 89 | property AppName: String read ReadName write WriteName; | ||
| 90 | property AppVersion: String read ReadVersion write WriteVersion; | ||
| 91 | procedure ReadAppLicense(info: TStringList); | ||
| 92 | procedure WriteAppLicense(path: String); | ||
| 93 | procedure WriteAppLicense(info: TStringList); | ||
| 94 | procedure ReadAppDescription(info: TStringList); | ||
| 95 | procedure WriteAppDescription(path: String); | ||
| 96 | procedure WriteAppDescription(info: TStringList); | ||
| 97 | property Icon: String read ReadIcon write WriteIcon; | ||
| 98 | property LangCode: String read clang write clang; | ||
| 99 | property SDesc: String read ReadSDesc write WriteSDesc; | ||
| 100 | property Category: AppCategory read ReadCategory write WriteCategory; | ||
| 101 | property Author: String read ReadAuthor write WriteAuthor; | ||
| 102 | property Maintainer: String read ReadMaintainer write WriteMaintainer; | ||
| 103 | property Disallows: String read ReadDisallows write WriteDisallows; | ||
| 104 | procedure ReadProfiles(lst: TStrings); | ||
| 105 | procedure WriteProfiles(lst: TStrings); | ||
| 106 | procedure ReadBuildCMDs(lst: TStrings); | ||
| 107 | procedure WriteBuildCMDs(lst: TStrings); | ||
| 108 | property AppCMD: String read ReadAppCMD write WriteAppCMD; | ||
| 109 | property Architecture: String read ReadArchs write WriteArchs; | ||
| 110 | property PkName: String read ReadPkgName write WritePkgName; | ||
| 111 | property IPKName: String read ReadIPKName write WriteIPKName; | ||
| 112 | property DSupport: String read ReadDSupport write WriteDSupport; | ||
| 113 | property WizImage: String read ReadWizImage write WriteWizImage; | ||
| 114 | property Binary: String read ReadBinary write WriteBinary; | ||
| 115 | property USource: String read ReadUSource write WriteUSource; | ||
| 116 | property Desktopfiles: String read ReadDesktopFiles write WriteDesktopFiles; | ||
| 117 | property InTerminal: Boolean read ReadInTerminal write WriteInTerminal; | ||
| 118 | procedure ReadDependencies(dname: String; info: TStringList); | ||
| 119 | procedure WriteDependencies(dname: String; path: String); | ||
| 120 | procedure WriteDependencies(dname: String; info: TStringList); | ||
| 121 | function LoadFromFile(s: String): Boolean; virtual; abstract; | ||
| 122 | property UseMoTranslation: Boolean read motrans write motrans; | ||
| 123 | procedure GetMoFileList(list: TStringList); | ||
| 124 | procedure SetMoFilesToDir(dir: String); | ||
| 125 | end; | ||
| 126 | |||
| 127 | TIPKControl = class; | ||
| 128 | |||
| 129 | //** Class to handle IPK scripts | ||
| 130 | TIPKScript = class(TIPKBasic) | ||
| 131 | private | ||
| 132 | fname: String; | ||
| 133 | public | ||
| 134 | constructor Create; | ||
| 135 | destructor Destroy; override; | ||
| 136 | |||
| 137 | function SaveToFile(s: String): Boolean; | ||
| 138 | function LoadFromFile(s: String): Boolean; override; | ||
| 139 | function LoadFromList(lst: TStrings): Boolean; | ||
| 140 | procedure GetFiles(id: Integer; lst: TStrings); | ||
| 141 | procedure GetDirectFileList(id: Integer; lst: TStrings); | ||
| 142 | function FinalizeToControl: TIPKControl; | ||
| 143 | end; | ||
| 144 | |||
| 145 | //** Class to read IPK control files | ||
| 146 | TIPKControl = class(TIPKBasic) | ||
| 147 | private | ||
| 148 | fname: String; | ||
| 149 | public | ||
| 150 | constructor Create; | ||
| 151 | constructor Create(path: String); | ||
| 152 | destructor Destroy; override; | ||
| 153 | |||
| 154 | function SaveToFile(s: String): Boolean; | ||
| 155 | procedure GetInternalFilesSection(lst: TStrings); | ||
| 156 | function LoadFromFile(s: String): Boolean; override; | ||
| 157 | |||
| 158 | property RawText: TStringList read text write text; | ||
| 159 | end; | ||
| 160 | |||
| 161 | implementation | ||
| 162 | |||
| 163 | { TIPKBasic } | ||
| 164 | |||
| 165 | constructor TIPKBasic.Create; | ||
| 166 | begin | ||
| 167 | inherited; | ||
| 168 | Text := TStringList.Create; | ||
| 169 | FBasePath := ExtractFilePath(ParamStr(0)); | ||
| 170 | clang := ''; | ||
| 171 | mofile := ''; | ||
| 172 | motrans := false; | ||
| 173 | end; | ||
| 174 | |||
| 175 | destructor TIPKBasic.Destroy; | ||
| 176 | begin | ||
| 177 | Text.Free; | ||
| 178 | inherited; | ||
| 179 | end; | ||
| 180 | |||
| 181 | procedure TIPKBasic.WriteEntry(k, s: String); | ||
| 182 | begin | ||
| 183 | s := k + ': ' + s; | ||
| 184 | if SearchKeyIndex(k) > -1 then | ||
| 185 | Text[SearchKeyIndex(k)] := s | ||
| 186 | else | ||
| 187 | Text.Add(s); | ||
| 188 | end; | ||
| 189 | |||
| 190 | function TIPKBasic.GetValue(s: String): String; | ||
| 191 | begin | ||
| 192 | if pos(':', s) = length(s) then | ||
| 193 | begin | ||
| 194 | //There is an empty block (without value) | ||
| 195 | Result := ''; | ||
| 196 | exit; | ||
| 197 | end; | ||
| 198 | Result := copy(s, pos(':', s) + 1, length(s)); | ||
| 199 | if (Result[1] = ' ') then | ||
| 200 | Result := copy(Result, 2, length(Result)); | ||
| 201 | end; | ||
| 202 | |||
| 203 | function TIPKBasic.SearchKeyIndex(S: String; localized: Boolean = true): Integer; | ||
| 204 | var | ||
| 205 | i: Integer; | ||
| 206 | h: String; | ||
| 207 | begin | ||
| 208 | Result := -1; | ||
| 209 | i := Text.Count; | ||
| 210 | //First search for localized entry | ||
| 211 | if (clang <> '') and (localized) then | ||
| 212 | begin | ||
| 213 | for i := 0 to Text.Count - 1 do | ||
| 214 | begin | ||
| 215 | if (length(Text[i])>0)and(Text[i][1]<>'#')and(Text[i][1]<>' ') then | ||
| 216 | begin | ||
| 217 | h := copy(Text[i], 0, pos(':', Text[i]) - 1); | ||
| 218 | if LowerCase(h) = LowerCase(s) + '[' + clang + ']' then | ||
| 219 | begin | ||
| 220 | Result := i; | ||
| 221 | break; | ||
| 222 | end; | ||
| 223 | end; | ||
| 224 | end; | ||
| 225 | end; | ||
| 226 | //Then search the general key | ||
| 227 | if (not localized) or (Result < 0) then | ||
| 228 | for i := 0 to Text.Count - 1 do | ||
| 229 | begin | ||
| 230 | if (length(Text[i])>0)and(Text[i][1]<>'#')and(Text[i][1]<>' ') then | ||
| 231 | begin | ||
| 232 | h := copy(Text[i], 0, pos(':', Text[i]) - 1); | ||
| 233 | if LowerCase(h) = LowerCase(s) then | ||
| 234 | begin | ||
| 235 | Result := i; | ||
| 236 | break; | ||
| 237 | end; | ||
| 238 | end; | ||
| 239 | end; | ||
| 240 | end; | ||
| 241 | |||
| 242 | function TIPKBasic.SolveInclude(s: String): String; | ||
| 243 | var | ||
| 244 | h: String; | ||
| 245 | begin | ||
| 246 | h := copy(s, pos('"', s) + 1, length(s)); | ||
| 247 | h := copy(h, 0, pos('"', h) - 1); | ||
| 248 | if not FilenameIsAbsolute(h) then | ||
| 249 | Result := AppendPathDelim(FBasePath) + h | ||
| 250 | else | ||
| 251 | Result := h; | ||
| 252 | end; | ||
| 253 | |||
| 254 | function TIPKBasic.Translate(s: String): String; | ||
| 255 | var | ||
| 256 | i: Integer; | ||
| 257 | mo: TMoFile; | ||
| 258 | begin | ||
| 259 | Result := s; | ||
| 260 | if mofile = '~' then | ||
| 261 | exit; | ||
| 262 | if mofile = '' then | ||
| 263 | begin | ||
| 264 | mofile := '~'; | ||
| 265 | for i := 0 to text.Count - 1 do | ||
| 266 | if pos('include:', Text[i]) > 0 then | ||
| 267 | if LowerCase(ExtractFileExt(SolveInclude(Text[i]))) = '.mo' then | ||
| 268 | begin | ||
| 269 | mofile := ExtractFileName(SolveInclude(Text[i])); | ||
| 270 | if (mofile = GetLangId + '.mo') or | ||
| 271 | (copy(mofile, pos('-', mofile) + 1, length(mofile)) = GetlangId + '.mo') then | ||
| 272 | break | ||
| 273 | else | ||
| 274 | mofile := '~'; | ||
| 275 | end; | ||
| 276 | end; | ||
| 277 | if (mofile = '~') or (trim(mofile) = '') or (not FileExists(FBasePath+mofile)) then | ||
| 278 | exit; | ||
| 279 | mo := TMoFile.Create(FBasePath+mofile); | ||
| 280 | Result := mo.Translate(s); | ||
| 281 | mo.Free; | ||
| 282 | end; | ||
| 283 | |||
| 284 | procedure TIPKBasic.GetMoFileList(list: TStringList); | ||
| 285 | var | ||
| 286 | i: Integer; | ||
| 287 | begin | ||
| 288 | for i := 0 to Text.Count - 1 do | ||
| 289 | if pos('include:', Text[i]) > 0 then | ||
| 290 | begin | ||
| 291 | if (ExtractFileExt(SolveInclude(text[i]))) = '.mo' then | ||
| 292 | list.Add(SolveInclude(text[i])); | ||
| 293 | end; | ||
| 294 | end; | ||
| 295 | |||
| 296 | procedure TIPKBasic.SetMoFilesToDir(dir: String); | ||
| 297 | var | ||
| 298 | list: TStringList; | ||
| 299 | i: Integer; | ||
| 300 | begin | ||
| 301 | list := TStringList.Create; | ||
| 302 | GetMoFileList(list); | ||
| 303 | i := 0; | ||
| 304 | while i < text.Count do | ||
| 305 | begin | ||
| 306 | if (pos('include:', text[i])>0) and(pos('.mo', text[i])>0) then | ||
| 307 | begin | ||
| 308 | text.Delete(i); | ||
| 309 | end | ||
| 310 | else | ||
| 311 | Inc(i); | ||
| 312 | end; | ||
| 313 | text.Insert(1, ''); | ||
| 314 | for i := 0 to list.Count-1 do | ||
| 315 | text.Insert(1, 'include:"'+dir+'/'+ExtractFileName(list[i])+'"'); | ||
| 316 | list.Free; | ||
| 317 | end; | ||
| 318 | |||
| 319 | procedure TIPKBasic.WriteField(Name: String; info: TStrings); | ||
| 320 | var | ||
| 321 | i: Integer; | ||
| 322 | begin | ||
| 323 | if info.Count >= 0 then | ||
| 324 | begin | ||
| 325 | i := SearchKeyIndex(Name); | ||
| 326 | if i > 0 then | ||
| 327 | begin | ||
| 328 | |||
| 329 | Text.Delete(i); | ||
| 330 | while (i < Text.Count) and (Text[i] <> '') and (Text[i][1] = ' ') do | ||
| 331 | Text.Delete(i); | ||
| 332 | end; | ||
| 333 | |||
| 334 | Text.Add(Name + ': ' + info[0]); | ||
| 335 | for i := 1 to info.Count - 1 do | ||
| 336 | Text.Add(' ' + info[i]); | ||
| 337 | end; | ||
| 338 | end; | ||
| 339 | |||
| 340 | procedure TIPKBasic.ReadField(Name: String; info: TStrings); | ||
| 341 | var | ||
| 342 | i: Integer; | ||
| 343 | s: String; | ||
| 344 | begin | ||
| 345 | i := SearchKeyIndex(Name); | ||
| 346 | s := ''; | ||
| 347 | if i > -1 then | ||
| 348 | s := Text[i]; | ||
| 349 | info.Clear; | ||
| 350 | if s = '' then | ||
| 351 | exit; | ||
| 352 | if pos('include:"', s) > 0 then | ||
| 353 | info.LoadFromFile(SolveInclude(s)) | ||
| 354 | else | ||
| 355 | begin | ||
| 356 | info.Add(GetValue(Text[i])); | ||
| 357 | Inc(i); | ||
| 358 | if i < Text.Count then | ||
| 359 | repeat | ||
| 360 | s := Text[i]; | ||
| 361 | if s[1] = ' ' then | ||
| 362 | begin | ||
| 363 | s := copy(s, 2, length(s)); | ||
| 364 | info.Add(s); | ||
| 365 | end; | ||
| 366 | Inc(i); | ||
| 367 | until (i >= Text.Count) or (Text[i][1] <> ' ') or (length(Text[i]) < 1); | ||
| 368 | end; | ||
| 369 | end; | ||
| 370 | |||
| 371 | procedure TIPKBasic.WriteType(atype: TPkgType); | ||
| 372 | var | ||
| 373 | h: String; | ||
| 374 | begin | ||
| 375 | case AType of | ||
| 376 | ptLinstall: h := 'Type: linstall'; | ||
| 377 | ptDLink: h := 'Type: dlink'; | ||
| 378 | ptContainer: h := 'Type: container'; | ||
| 379 | end; | ||
| 380 | if SearchKeyIndex('Type', false) > -1 then | ||
| 381 | Text[SearchKeyIndex('Type', false)] := h | ||
| 382 | else | ||
| 383 | Text.Add(h); | ||
| 384 | end; | ||
| 385 | |||
| 386 | function TIPKBasic.ReadType: TPkgType; | ||
| 387 | var | ||
| 388 | s: String; | ||
| 389 | j: Integer; | ||
| 390 | begin | ||
| 391 | Result := ptUnknown; | ||
| 392 | j := SearchKeyIndex('Type', false); | ||
| 393 | |||
| 394 | if j > -1 then | ||
| 395 | begin | ||
| 396 | s := Text[j]; | ||
| 397 | writeLn(s); | ||
| 398 | if GetValue(s) = 'linstall' then | ||
| 399 | Result := ptLinstall; | ||
| 400 | if GetValue(s) = 'dlink' then | ||
| 401 | Result := ptDLink; | ||
| 402 | if GetValue(s) = 'container' then | ||
| 403 | Result := ptContainer; | ||
| 404 | end; | ||
| 405 | end; | ||
| 406 | |||
| 407 | procedure TIPKBasic.WriteName(s: String); | ||
| 408 | var | ||
| 409 | k: String; | ||
| 410 | begin | ||
| 411 | if clang = '' then | ||
| 412 | k := 'Name' | ||
| 413 | else | ||
| 414 | k := 'Name[' + clang + ']'; | ||
| 415 | |||
| 416 | WriteEntry(k, s); | ||
| 417 | end; | ||
| 418 | |||
| 419 | function TIPKBasic.ReadName: String; | ||
| 420 | var | ||
| 421 | j: Integer; | ||
| 422 | begin | ||
| 423 | Result := ''; | ||
| 424 | j := SearchKeyIndex('Name'); | ||
| 425 | if j > -1 then | ||
| 426 | Result := GetValue(Text[j]); | ||
| 427 | Result := translate(Result); | ||
| 428 | end; | ||
| 429 | |||
| 430 | procedure TIPKBasic.WriteVersion(s: String); | ||
| 431 | var | ||
| 432 | k: String; | ||
| 433 | begin | ||
| 434 | if clang = '' then | ||
| 435 | k := 'Version' | ||
| 436 | else | ||
| 437 | k := 'Version[' + clang + ']'; | ||
| 438 | |||
| 439 | WriteEntry(k, s); | ||
| 440 | end; | ||
| 441 | |||
| 442 | function TIPKBasic.ReadVersion: String; | ||
| 443 | var | ||
| 444 | j: Integer; | ||
| 445 | begin | ||
| 446 | Result := ''; | ||
| 447 | j := SearchKeyIndex('Version'); | ||
| 448 | if j > -1 then | ||
| 449 | Result := GetValue(Text[j]); | ||
| 450 | end; | ||
| 451 | |||
| 452 | procedure TIPKBasic.ReadAppLicense(info: TStringList); | ||
| 453 | begin | ||
| 454 | ReadField('License', info); | ||
| 455 | end; | ||
| 456 | |||
| 457 | procedure TIPKBasic.WriteAppLicense(path: String); | ||
| 458 | var | ||
| 459 | s: String; | ||
| 460 | i: Integer; | ||
| 461 | begin | ||
| 462 | s := 'License: include:"' + path + '"'; | ||
| 463 | |||
| 464 | i := SearchKeyIndex('License'); | ||
| 465 | if i > 0 then | ||
| 466 | begin | ||
| 467 | Text.Delete(i); | ||
| 468 | while (i < Text.Count) and (Text[i][1] = ' ') do | ||
| 469 | Text.Delete(i); | ||
| 470 | end; | ||
| 471 | |||
| 472 | if i > -1 then | ||
| 473 | Text[i] := s | ||
| 474 | else | ||
| 475 | Text.Add(s); | ||
| 476 | end; | ||
| 477 | |||
| 478 | procedure TIPKBasic.WriteAppLicense(info: TStringList); | ||
| 479 | begin | ||
| 480 | WriteField('License', info); | ||
| 481 | end; | ||
| 482 | |||
| 483 | procedure TIPKBasic.ReadAppDescription(info: TStringList); | ||
| 484 | begin | ||
| 485 | ReadField('Description', info); | ||
| 486 | end; | ||
| 487 | |||
| 488 | procedure TIPKBasic.WriteAppDescription(path: String); | ||
| 489 | var | ||
| 490 | s: String; | ||
| 491 | i: Integer; | ||
| 492 | begin | ||
| 493 | s := 'Description: include:"' + path + '"'; | ||
| 494 | |||
| 495 | i := SearchKeyIndex('Description'); | ||
| 496 | if i > 0 then | ||
| 497 | begin | ||
| 498 | Text.Delete(i); | ||
| 499 | while (i < Text.Count) and (Text[i][1] = ' ') do | ||
| 500 | Text.Delete(i); | ||
| 501 | end; | ||
| 502 | |||
| 503 | if i > -1 then | ||
| 504 | Text[i] := s | ||
| 505 | else | ||
| 506 | Text.Add(s); | ||
| 507 | end; | ||
| 508 | |||
| 509 | procedure TIPKBasic.WriteAppDescription(info: TStringList); | ||
| 510 | begin | ||
| 511 | WriteField('Description', info); | ||
| 512 | end; | ||
| 513 | |||
| 514 | procedure TIPKBasic.WriteIcon(s: String); | ||
| 515 | begin | ||
| 516 | WriteEntry('Icon', s); | ||
| 517 | end; | ||
| 518 | |||
| 519 | function TIPKBasic.ReadIcon: String; | ||
| 520 | var | ||
| 521 | j: Integer; | ||
| 522 | begin | ||
| 523 | Result := ''; | ||
| 524 | j := SearchKeyIndex('Icon', false); | ||
| 525 | if j > -1 then | ||
| 526 | Result := GetValue(Text[j]); | ||
| 527 | end; | ||
| 528 | |||
| 529 | procedure TIPKBasic.WriteSDesc(s: String); | ||
| 530 | var | ||
| 531 | k: String; | ||
| 532 | begin | ||
| 533 | if clang = '' then | ||
| 534 | k := 'SDesc' | ||
| 535 | else | ||
| 536 | k := 'SDesc[' + clang + ']'; | ||
| 537 | |||
| 538 | WriteEntry(k, s); | ||
| 539 | end; | ||
| 540 | |||
| 541 | function TIPKBasic.ReadSDesc: String; | ||
| 542 | var | ||
| 543 | j: Integer; | ||
| 544 | begin | ||
| 545 | Result := ''; | ||
| 546 | j := SearchKeyIndex('SDesc'); | ||
| 547 | if j > -1 then | ||
| 548 | Result := GetValue(Text[j]); | ||
| 549 | |||
| 550 | Result := translate(Result); | ||
| 551 | end; | ||
| 552 | |||
| 553 | procedure TIPKBasic.WriteCategory(g: AppCategory); | ||
| 554 | var | ||
| 555 | s: String; | ||
| 556 | begin | ||
| 557 | case g of | ||
| 558 | gtALL: s := 'All'; | ||
| 559 | gtEDUCATION: s := 'Education'; | ||
| 560 | gtOFFICE: s := 'Office'; | ||
| 561 | gtDEVELOPMENT: s := 'Development'; | ||
| 562 | gtGRAPHIC: s := 'Graphic'; | ||
| 563 | gtNETWORK: s := 'Network'; | ||
| 564 | gtGAMES: s := 'Games'; | ||
| 565 | gtSYSTEM: s := 'System'; | ||
| 566 | gtMULTIMEDIA: s := 'Multimedia'; | ||
| 567 | gtADDITIONAL: s := 'Additional'; | ||
| 568 | gtOTHER: s := 'Other'; | ||
| 569 | end; | ||
| 570 | s := 'Group: ' + s; | ||
| 571 | |||
| 572 | if SearchKeyIndex('Group', false) > -1 then | ||
| 573 | Text[SearchKeyIndex('Group', false)] := s | ||
| 574 | else | ||
| 575 | Text.Add(s); | ||
| 576 | end; | ||
| 577 | |||
| 578 | function TIPKBasic.ReadCategory: AppCategory; | ||
| 579 | var | ||
| 580 | j: Integer; | ||
| 581 | s: String; | ||
| 582 | begin | ||
| 583 | Result := gtUNKNOWN; | ||
| 584 | j := SearchKeyIndex('Group', false); | ||
| 585 | if j > -1 then | ||
| 586 | s := GetValue(Text[j]); | ||
| 587 | |||
| 588 | s := LowerCase(s); | ||
| 589 | if s = 'all' then | ||
| 590 | Result := gtALL; | ||
| 591 | if s = 'education' then | ||
| 592 | Result := gtEDUCATION; | ||
| 593 | if s = 'office' then | ||
| 594 | Result := gtOFFICE; | ||
| 595 | if s = 'development' then | ||
| 596 | Result := gtDEVELOPMENT; | ||
| 597 | if s = 'graphic' then | ||
| 598 | Result := gtGRAPHIC; | ||
| 599 | if s = 'network' then | ||
| 600 | Result := gtNETWORK; | ||
| 601 | if s = 'games' then | ||
| 602 | Result := gtGAMES; | ||
| 603 | if s = 'system' then | ||
| 604 | Result := gtSYSTEM; | ||
| 605 | if s = 'multimedia' then | ||
| 606 | Result := gtMULTIMEDIA; | ||
| 607 | if s = 'additional' then | ||
| 608 | Result := gtADDITIONAL; | ||
| 609 | if s = 'other' then | ||
| 610 | Result := gtOTHER; | ||
| 611 | end; | ||
| 612 | |||
| 613 | procedure TIPKBasic.ReadBuildCMDs(lst: TStrings); | ||
| 614 | begin | ||
| 615 | ReadField('Build', lst); | ||
| 616 | end; | ||
| 617 | |||
| 618 | procedure TIPKBasic.WriteBuildCMDs(lst: TStrings); | ||
| 619 | begin | ||
| 620 | WriteField('Build', lst); | ||
| 621 | end; | ||
| 622 | |||
| 623 | procedure TIPKBasic.WriteAuthor(s: String); | ||
| 624 | var | ||
| 625 | k: String; | ||
| 626 | begin | ||
| 627 | if clang = '' then | ||
| 628 | k := 'Author' | ||
| 629 | else | ||
| 630 | k := 'Author[' + clang + ']'; | ||
| 631 | |||
| 632 | WriteEntry(k, s); | ||
| 633 | end; | ||
| 634 | |||
| 635 | function TIPKBasic.ReadAuthor: String; | ||
| 636 | var | ||
| 637 | j: Integer; | ||
| 638 | begin | ||
| 639 | Result := ''; | ||
| 640 | j := SearchKeyIndex('Author'); | ||
| 641 | if j > -1 then | ||
| 642 | Result := GetValue(Text[j]); | ||
| 643 | Result := translate(Result); | ||
| 644 | end; | ||
| 645 | |||
| 646 | procedure TIPKBasic.WriteMaintainer(s: String); | ||
| 647 | var | ||
| 648 | k: String; | ||
| 649 | begin | ||
| 650 | if clang = '' then | ||
| 651 | k := 'Maintainer' | ||
| 652 | else | ||
| 653 | k := 'Maintainer[' + clang + ']'; | ||
| 654 | |||
| 655 | WriteEntry(k, s); | ||
| 656 | end; | ||
| 657 | |||
| 658 | function TIPKBasic.ReadMaintainer: String; | ||
| 659 | var | ||
| 660 | j: Integer; | ||
| 661 | begin | ||
| 662 | Result := ''; | ||
| 663 | j := SearchKeyIndex('Maintainer'); | ||
| 664 | if j > -1 then | ||
| 665 | Result := GetValue(Text[j]); | ||
| 666 | Result := translate(Result); | ||
| 667 | end; | ||
| 668 | |||
| 669 | procedure TIPKBasic.WriteDisallows(s: String); | ||
| 670 | var | ||
| 671 | k: String; | ||
| 672 | begin | ||
| 673 | k := 'Disallow'; | ||
| 674 | WriteEntry(k, s); | ||
| 675 | end; | ||
| 676 | |||
| 677 | function TIPKBasic.ReadDisallows: String; | ||
| 678 | var | ||
| 679 | j: Integer; | ||
| 680 | begin | ||
| 681 | Result := ''; | ||
| 682 | j := SearchKeyIndex('Disallow', false); | ||
| 683 | if j > -1 then | ||
| 684 | Result := GetValue(Text[j]); | ||
| 685 | end; | ||
| 686 | |||
| 687 | procedure TIPKBasic.WriteProfiles(lst: TStrings); | ||
| 688 | var | ||
| 689 | k, s: String; | ||
| 690 | i: Integer; | ||
| 691 | begin | ||
| 692 | k := 'Profile['; | ||
| 693 | for i := 0 to lst.Count - 1 do | ||
| 694 | begin | ||
| 695 | s := k + IntToStr(i) + ']: ' + lst[i]; | ||
| 696 | if SearchKeyIndex(k) > -1 then | ||
| 697 | Text[SearchKeyIndex(k)] := s | ||
| 698 | else | ||
| 699 | Text.Add(s); | ||
| 700 | end; | ||
| 701 | end; | ||
| 702 | |||
| 703 | procedure TIPKBasic.ReadProfiles(lst: TStrings); | ||
| 704 | var | ||
| 705 | j: Integer; | ||
| 706 | |||
| 707 | function GetProfileName(id: Integer): String; | ||
| 708 | var | ||
| 709 | i: Integer; | ||
| 710 | begin | ||
| 711 | Result := ''; | ||
| 712 | i := SearchKeyIndex('Profiles[' + IntToStr(id) + ']'); | ||
| 713 | if (id = 0) and (i < 0) then | ||
| 714 | i := SearchKeyIndex('Profiles'); | ||
| 715 | if i > -1 then | ||
| 716 | Result := GetValue(Text[i]); | ||
| 717 | end; | ||
| 718 | |||
| 719 | begin | ||
| 720 | j := 0; | ||
| 721 | repeat | ||
| 722 | lst.Add(GetProfileName(j)); | ||
| 723 | Inc(j); | ||
| 724 | until GetProfileName(j) = ''; | ||
| 725 | end; | ||
| 726 | |||
| 727 | procedure TIPKBasic.WriteAppCMD(s: String); | ||
| 728 | var | ||
| 729 | k: String; | ||
| 730 | begin | ||
| 731 | k := 'AppCMD'; | ||
| 732 | |||
| 733 | WriteEntry(k, s); | ||
| 734 | end; | ||
| 735 | |||
| 736 | function TIPKBasic.ReadAppCMD: String; | ||
| 737 | var | ||
| 738 | j: Integer; | ||
| 739 | begin | ||
| 740 | Result := ''; | ||
| 741 | j := SearchKeyIndex('AppCMD', false); | ||
| 742 | if j > -1 then | ||
| 743 | Result := GetValue(Text[j]); | ||
| 744 | end; | ||
| 745 | |||
| 746 | procedure TIPKBasic.WriteArchs(s: String); | ||
| 747 | var | ||
| 748 | k: String; | ||
| 749 | begin | ||
| 750 | k := 'Architecture'; | ||
| 751 | WriteEntry(k, s); | ||
| 752 | end; | ||
| 753 | |||
| 754 | function TIPKBasic.ReadArchs: String; | ||
| 755 | var | ||
| 756 | j: Integer; | ||
| 757 | begin | ||
| 758 | Result := ''; | ||
| 759 | j := SearchKeyIndex('Architecture', false); | ||
| 760 | if j > -1 then | ||
| 761 | Result := GetValue(Text[j]); | ||
| 762 | end; | ||
| 763 | |||
| 764 | procedure TIPKBasic.WritePkgName(s: String); | ||
| 765 | var | ||
| 766 | k: String; | ||
| 767 | begin | ||
| 768 | k := 'PkName'; | ||
| 769 | WriteEntry(k, s); | ||
| 770 | end; | ||
| 771 | |||
| 772 | function TIPKBasic.ReadPkgName: String; | ||
| 773 | var | ||
| 774 | j: Integer; | ||
| 775 | begin | ||
| 776 | Result := ''; | ||
| 777 | j := SearchKeyIndex('PkName', false); | ||
| 778 | if j > -1 then | ||
| 779 | Result := GetValue(Text[j]); | ||
| 780 | end; | ||
| 781 | |||
| 782 | procedure TIPKBasic.WriteIPKName(s: String); | ||
| 783 | var | ||
| 784 | k: String; | ||
| 785 | begin | ||
| 786 | k := 'IPKName'; | ||
| 787 | WriteEntry(k, s); | ||
| 788 | end; | ||
| 789 | |||
| 790 | function TIPKBasic.ReadIPKName: String; | ||
| 791 | var | ||
| 792 | j: Integer; | ||
| 793 | begin | ||
| 794 | Result := ''; | ||
| 795 | j := SearchKeyIndex('IPKName', false); | ||
| 796 | if j > -1 then | ||
| 797 | Result := GetValue(Text[j]); | ||
| 798 | end; | ||
| 799 | |||
| 800 | procedure TIPKBasic.WriteDSupport(s: String); | ||
| 801 | var | ||
| 802 | k: String; | ||
| 803 | begin | ||
| 804 | k := 'DSupport'; | ||
| 805 | WriteEntry(k, s); | ||
| 806 | end; | ||
| 807 | |||
| 808 | function TIPKBasic.ReadDSupport: String; | ||
| 809 | var | ||
| 810 | j: Integer; | ||
| 811 | begin | ||
| 812 | Result := ''; | ||
| 813 | j := SearchKeyIndex('DSupport', false); | ||
| 814 | if j > -1 then | ||
| 815 | Result := GetValue(Text[j]); | ||
| 816 | end; | ||
| 817 | |||
| 818 | procedure TIPKBasic.ReadDependencies(dname: String; info: TStringList); | ||
| 819 | var | ||
| 820 | i: Integer; | ||
| 821 | s: String; | ||
| 822 | begin | ||
| 823 | if (dname = 'all') or (dname = '') then | ||
| 824 | i := SearchKeyIndex('Dependencies', false) | ||
| 825 | else | ||
| 826 | i := SearchKeyIndex('Dependencies[' + dname + ']', false); | ||
| 827 | |||
| 828 | s := ''; | ||
| 829 | if i > -1 then | ||
| 830 | s := Text[i]; | ||
| 831 | info.Clear; | ||
| 832 | |||
| 833 | if s = '' then | ||
| 834 | exit; | ||
| 835 | if pos('include:"', s) > 0 then | ||
| 836 | info.LoadFromFile(SolveInclude(s)) | ||
| 837 | else | ||
| 838 | begin | ||
| 839 | info.Add(GetValue(Text[i])); | ||
| 840 | Inc(i); | ||
| 841 | repeat | ||
| 842 | s := Text[i]; | ||
| 843 | if length(s) > 0 then | ||
| 844 | if s[1] = ' ' then | ||
| 845 | begin | ||
| 846 | s := copy(s, 2, length(s)); | ||
| 847 | info.Add(s); | ||
| 848 | end; | ||
| 849 | Inc(i); | ||
| 850 | until (length(Text[i]) = 0) or (i >= Text.Count) or (Text[i][1] <> ' '); | ||
| 851 | end; | ||
| 852 | end; | ||
| 853 | |||
| 854 | procedure TIPKBasic.WriteDependencies(dname: String; path: String); | ||
| 855 | var | ||
| 856 | s: String; | ||
| 857 | i: Integer; | ||
| 858 | begin | ||
| 859 | if (dname = 'all') or (dname = '') then | ||
| 860 | s := 'Dependencies: include:"' + path + '"' | ||
| 861 | else | ||
| 862 | s := 'Dependencies[' + dname + ']: include:"' + path + '"'; | ||
| 863 | |||
| 864 | i := SearchKeyIndex('Dependencies'); | ||
| 865 | if i > 0 then | ||
| 866 | begin | ||
| 867 | Text.Delete(i); | ||
| 868 | while (i < Text.Count) and (Text[i][1] = ' ') do | ||
| 869 | Text.Delete(i); | ||
| 870 | end; | ||
| 871 | |||
| 872 | if i > -1 then | ||
| 873 | Text[i] := s | ||
| 874 | else | ||
| 875 | Text.Add(s); | ||
| 876 | end; | ||
| 877 | |||
| 878 | procedure TIPKBasic.WriteDependencies(dname: String; info: TStringList); | ||
| 879 | var | ||
| 880 | i: Integer; | ||
| 881 | s: String; | ||
| 882 | begin | ||
| 883 | if info.Count >= 0 then | ||
| 884 | begin | ||
| 885 | if (dname = 'all') or (dname = '') then | ||
| 886 | begin | ||
| 887 | s := 'Dependencies'; | ||
| 888 | i := SearchKeyIndex(s, false); | ||
| 889 | end | ||
| 890 | else | ||
| 891 | begin | ||
| 892 | s := 'Dependencies[' + dname + ']'; | ||
| 893 | i := SearchKeyIndex(s, false); | ||
| 894 | end; | ||
| 895 | |||
| 896 | if i > 0 then | ||
| 897 | begin | ||
| 898 | |||
| 899 | Text.Delete(i); | ||
| 900 | while (i < Text.Count) and (Text[i] <> '') and (Text[i][1] = ' ') do | ||
| 901 | Text.Delete(i); | ||
| 902 | end; | ||
| 903 | |||
| 904 | Text.Add(s + ': ' + info[0]); | ||
| 905 | for i := 1 to info.Count - 1 do | ||
| 906 | Text.Add(' ' + info[i]); | ||
| 907 | |||
| 908 | end; | ||
| 909 | end; | ||
| 910 | |||
| 911 | procedure TIPKBasic.WriteWizImage(s: String); | ||
| 912 | var | ||
| 913 | k: String; | ||
| 914 | begin | ||
| 915 | k := 'WizImage'; | ||
| 916 | WriteEntry(k, s); | ||
| 917 | end; | ||
| 918 | |||
| 919 | function TIPKBasic.ReadWizImage: String; | ||
| 920 | var | ||
| 921 | j: Integer; | ||
| 922 | begin | ||
| 923 | Result := ''; | ||
| 924 | j := SearchKeyIndex('WizImage', false); | ||
| 925 | if j > -1 then | ||
| 926 | Result := GetValue(Text[j]); | ||
| 927 | end; | ||
| 928 | |||
| 929 | procedure TIPKBasic.WriteBinary(s: String); | ||
| 930 | begin | ||
| 931 | WriteEntry('Binary', s); | ||
| 932 | end; | ||
| 933 | |||
| 934 | function TIPKBasic.ReadBinary: String; | ||
| 935 | var | ||
| 936 | j: Integer; | ||
| 937 | begin | ||
| 938 | Result := ''; | ||
| 939 | j := SearchKeyIndex('Binary', false); | ||
| 940 | if j > -1 then | ||
| 941 | Result := GetValue(Text[j]); | ||
| 942 | end; | ||
| 943 | |||
| 944 | procedure TIPKBasic.WriteUSource(s: String); | ||
| 945 | begin | ||
| 946 | WriteEntry('USource', s); | ||
| 947 | end; | ||
| 948 | |||
| 949 | function TIPKBasic.ReadUSource: String; | ||
| 950 | var | ||
| 951 | j: Integer; | ||
| 952 | begin | ||
| 953 | Result := ''; | ||
| 954 | j := SearchKeyIndex('USource', false); | ||
| 955 | if j > -1 then | ||
| 956 | Result := GetValue(Text[j]); | ||
| 957 | end; | ||
| 958 | |||
| 959 | procedure TIPKBasic.WriteDesktopFiles(s: String); | ||
| 960 | begin | ||
| 961 | WriteEntry('Desktopfiles', s); | ||
| 962 | end; | ||
| 963 | |||
| 964 | function TIPKBasic.ReadDesktopFiles: String; | ||
| 965 | var | ||
| 966 | j: Integer; | ||
| 967 | begin | ||
| 968 | Result := ''; | ||
| 969 | j := SearchKeyIndex('Desktopfiles', false); | ||
| 970 | if j > -1 then | ||
| 971 | Result := GetValue(Text[j]); | ||
| 972 | end; | ||
| 973 | |||
| 974 | procedure TIPKBasic.WriteInTerminal(b: Boolean); | ||
| 975 | begin | ||
| 976 | if b = true then | ||
| 977 | WriteEntry('Desktopfiles', 'true') | ||
| 978 | else | ||
| 979 | WriteEntry('Desktopfiles', 'false'); | ||
| 980 | end; | ||
| 981 | |||
| 982 | function TIPKBasic.ReadInTerminal: Boolean; | ||
| 983 | var | ||
| 984 | j: Integer; | ||
| 985 | s: String; | ||
| 986 | begin | ||
| 987 | j := SearchKeyIndex('InTerminal', false); | ||
| 988 | if j > -1 then | ||
| 989 | s := GetValue(Text[j]); | ||
| 990 | if LowerCase(s) = 'true' then | ||
| 991 | Result := true | ||
| 992 | else | ||
| 993 | Result := false; | ||
| 994 | end; | ||
| 995 | |||
| 996 | { TIPKScript } | ||
| 997 | |||
| 998 | constructor TIPKScript.Create; | ||
| 999 | begin | ||
| 1000 | inherited; | ||
| 1001 | Text.Add('IPK-Standard-Version: 1.1'); | ||
| 1002 | Text.Add(''); | ||
| 1003 | fname := ''; | ||
| 1004 | end; | ||
| 1005 | |||
| 1006 | destructor TIPKScript.Destroy; | ||
| 1007 | begin | ||
| 1008 | inherited; | ||
| 1009 | end; | ||
| 1010 | |||
| 1011 | function TIPKScript.SaveToFile(s: String): Boolean; | ||
| 1012 | begin | ||
| 1013 | Result := true; | ||
| 1014 | try | ||
| 1015 | Text.SaveTofile(s); | ||
| 1016 | FBasePath := ExtractFilePath(s); | ||
| 1017 | fname := s; | ||
| 1018 | except | ||
| 1019 | Result := false; | ||
| 1020 | end; | ||
| 1021 | end; | ||
| 1022 | |||
| 1023 | function TIPKScript.LoadFromFile(s: String): Boolean; | ||
| 1024 | begin | ||
| 1025 | Result := true; | ||
| 1026 | if FileExists(s) then | ||
| 1027 | begin | ||
| 1028 | Text.LoadFromFile(s); | ||
| 1029 | if (Text[0] <> 'IPK-Standard-Version: 1.1') | ||
| 1030 | and(Text[0] <> 'IPK-Standard-Version: 1.0') then | ||
| 1031 | begin | ||
| 1032 | Result := false; | ||
| 1033 | Text.Clear; | ||
| 1034 | Text.Add('IPK-Standard-Version: 1.1'); | ||
| 1035 | Text.Add(''); | ||
| 1036 | exit; | ||
| 1037 | end; | ||
| 1038 | FBasePath := ExtractFilePath(s); | ||
| 1039 | fname := s; | ||
| 1040 | end | ||
| 1041 | else | ||
| 1042 | Result := false; | ||
| 1043 | end; | ||
| 1044 | |||
| 1045 | function TIPKScript.LoadFromList(lst: TStrings): Boolean; | ||
| 1046 | begin | ||
| 1047 | Result := true; | ||
| 1048 | writeLn(lst[0]); | ||
| 1049 | if (lst[0] <> 'IPK-Standard-Version: 1.1') | ||
| 1050 | and(lst[0] <> 'IPK-Standard-Version: 1.0') then | ||
| 1051 | begin | ||
| 1052 | Result := false; | ||
| 1053 | exit; | ||
| 1054 | end | ||
| 1055 | else | ||
| 1056 | Text.Assign(lst); | ||
| 1057 | end; | ||
| 1058 | |||
| 1059 | function TIPKScript.FinalizeToControl: TIPKControl; | ||
| 1060 | var | ||
| 1061 | i: Integer; | ||
| 1062 | cont: TIPKControl; | ||
| 1063 | |||
| 1064 | procedure ProcessLine(ln: String); | ||
| 1065 | begin | ||
| 1066 | if length(ln) > 0 then | ||
| 1067 | begin | ||
| 1068 | if ln[1] = '#' then | ||
| 1069 | exit; | ||
| 1070 | end; | ||
| 1071 | |||
| 1072 | if pos('#', ln) > 0 then | ||
| 1073 | ln := copy(ln, pos('#', ln) + 1, length(ln)); | ||
| 1074 | |||
| 1075 | if pos('IPKName:', ln) > 0 then | ||
| 1076 | exit; | ||
| 1077 | |||
| 1078 | cont.RawText.Add(ln); | ||
| 1079 | end; | ||
| 1080 | |||
| 1081 | begin | ||
| 1082 | cont := TIPKControl.Create; | ||
| 1083 | |||
| 1084 | for i := 0 to Text.Count - 1 do | ||
| 1085 | if pos('!-Files', Text[i]) <= 0 then | ||
| 1086 | ProcessLine(Text[i]); | ||
| 1087 | |||
| 1088 | Result := cont; | ||
| 1089 | end; | ||
| 1090 | |||
| 1091 | procedure TIPKScript.GetDirectFileList(id: Integer; lst: TStrings); | ||
| 1092 | var | ||
| 1093 | i, j: Integer; | ||
| 1094 | s: String; | ||
| 1095 | fsec: TStringList; | ||
| 1096 | begin | ||
| 1097 | fsec := TStringList.Create; | ||
| 1098 | for j := 0 to Text.Count - 1 do | ||
| 1099 | if pos('!-Files ~' + IntToStr(id), Text[j]) > 0 then | ||
| 1100 | break; | ||
| 1101 | |||
| 1102 | for i := j + 1 to Text.Count - 1 do | ||
| 1103 | if pos('!-Files ~', Text[i]) > 0 then | ||
| 1104 | break | ||
| 1105 | else | ||
| 1106 | fsec.Add(Text[i]); | ||
| 1107 | |||
| 1108 | i := 0; | ||
| 1109 | while i < fsec.Count - 1 do | ||
| 1110 | begin | ||
| 1111 | |||
| 1112 | if fsec[i][1] = '>' then | ||
| 1113 | s := copy(fsec[i], 2, length(fsec[i])) | ||
| 1114 | else | ||
| 1115 | begin | ||
| 1116 | if (fsec[i][1] = '/') or (fsec[i][1] = '.') then | ||
| 1117 | begin | ||
| 1118 | lst.Add(s); | ||
| 1119 | if fsec[i][1] = '.' then | ||
| 1120 | lst.Add(FBasePath + fsec[i]) | ||
| 1121 | else | ||
| 1122 | lst.Add(fsec[i]); | ||
| 1123 | end; | ||
| 1124 | end; | ||
| 1125 | Inc(i); | ||
| 1126 | end; | ||
| 1127 | end; | ||
| 1128 | |||
| 1129 | procedure TIPKScript.GetFiles(id: Integer; lst: TStrings); | ||
| 1130 | var | ||
| 1131 | i, j: Integer; | ||
| 1132 | begin | ||
| 1133 | //Search for container-IPK files section | ||
| 1134 | j := SearchKeyIndex('Files'); | ||
| 1135 | if j > -1 then | ||
| 1136 | begin | ||
| 1137 | ReadField('Files', lst); | ||
| 1138 | end | ||
| 1139 | else | ||
| 1140 | begin | ||
| 1141 | //Read normal files section | ||
| 1142 | for j := 0 to Text.Count - 1 do | ||
| 1143 | if pos('!-Files ~' + IntToStr(id), Text[j]) > 0 then | ||
| 1144 | break; | ||
| 1145 | |||
| 1146 | for i := j + 1 to Text.Count - 1 do | ||
| 1147 | if pos('!-Files ~', Text[i]) > 0 then | ||
| 1148 | break | ||
| 1149 | else | ||
| 1150 | lst.Add(Text[i]); | ||
| 1151 | end; | ||
| 1152 | end; | ||
| 1153 | |||
| 1154 | { TIPKControl } | ||
| 1155 | |||
| 1156 | constructor TIPKControl.Create(path: String); | ||
| 1157 | begin | ||
| 1158 | inherited Create; | ||
| 1159 | |||
| 1160 | LoadFromFile(path); | ||
| 1161 | FBasePath := ExtractFilePath(path); | ||
| 1162 | |||
| 1163 | fname := path; | ||
| 1164 | end; | ||
| 1165 | |||
| 1166 | constructor TIPKControl.Create; | ||
| 1167 | begin | ||
| 1168 | inherited Create; | ||
| 1169 | fname := ''; | ||
| 1170 | FBasePath := ''; | ||
| 1171 | end; | ||
| 1172 | |||
| 1173 | destructor TIPKControl.Destroy; | ||
| 1174 | begin | ||
| 1175 | inherited; | ||
| 1176 | end; | ||
| 1177 | |||
| 1178 | function TIPKControl.SaveToFile(s: String): Boolean; | ||
| 1179 | begin | ||
| 1180 | Result := true; | ||
| 1181 | try | ||
| 1182 | Text.SaveTofile(s); | ||
| 1183 | FBasePath := ExtractFilePath(s); | ||
| 1184 | fname := s; | ||
| 1185 | except | ||
| 1186 | Result := false; | ||
| 1187 | end; | ||
| 1188 | end; | ||
| 1189 | |||
| 1190 | function TIPKControl.LoadFromFile(s: String): Boolean; | ||
| 1191 | begin | ||
| 1192 | Result := true; | ||
| 1193 | if FileExists(s) then | ||
| 1194 | begin | ||
| 1195 | Text.LoadFromFile(s); | ||
| 1196 | if (Text[0] <> 'IPK-Standard-Version: 1.1') | ||
| 1197 | and(Text[0] <> 'IPK-Standard-Version: 1.0') then | ||
| 1198 | begin | ||
| 1199 | Result := false; | ||
| 1200 | exit; | ||
| 1201 | end; | ||
| 1202 | FBasePath := ExtractFilePath(s); | ||
| 1203 | fname := s; | ||
| 1204 | end | ||
| 1205 | else | ||
| 1206 | Result := false; | ||
| 1207 | |||
| 1208 | UseMoTranslation := true; | ||
| 1209 | end; | ||
| 1210 | |||
| 1211 | procedure TIPKControl.GetInternalFilesSection(lst: TStrings); | ||
| 1212 | var | ||
| 1213 | j: Integer; | ||
| 1214 | begin | ||
| 1215 | //Search for container-IPK files section | ||
| 1216 | j := SearchKeyIndex('Files', false); | ||
| 1217 | if j > -1 then | ||
| 1218 | begin | ||
| 1219 | ReadField('Files', lst); | ||
| 1220 | end; | ||
| 1221 | end; | ||
| 1222 | |||
| 1223 | end. |
src/ipkdef.pas
(0 / 1223)
|   | |||
| 1 | { Copyright (C) 2008-2010 Matthias Klumpp | ||
| 2 | |||
| 3 | Authors: | ||
| 4 | Matthias Klumpp | ||
| 5 | |||
| 6 | This unit is free software: you can redistribute it and/or modify it under | ||
| 7 | the terms of the GNU General Public License as published by the Free Software | ||
| 8 | Foundation, version 3. | ||
| 9 | |||
| 10 | This unit is distributed in the hope that it will be useful, but WITHOUT | ||
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License v3 | ||
| 15 | along with this unit. If not, see <http://www.gnu.org/licenses/>.} | ||
| 16 | //** Contains classes to process IPK files | ||
| 17 | unit ipkdef; | ||
| 18 | |||
| 19 | {$mode objfpc}{$H+} | ||
| 20 | |||
| 21 | interface | ||
| 22 | |||
| 23 | uses | ||
| 24 | Classes, GetText, liTypes, liUtils, SysUtils, FileUtil; | ||
| 25 | |||
| 26 | type | ||
| 27 | |||
| 28 | //** Basic IPK reader class | ||
| 29 | TIPKBasic = class | ||
| 30 | private | ||
| 31 | function GetValue(s: String): String; | ||
| 32 | function SearchKeyIndex(s: String; localized: Boolean = true): Integer; | ||
| 33 | function SolveInclude(s: String): String; | ||
| 34 | function translate(s: String): String; | ||
| 35 | procedure WriteEntry(k, s: String); | ||
| 36 | |||
| 37 | procedure WriteType(atype: TPkgType); | ||
| 38 | function ReadType: TPkgType; | ||
| 39 | procedure WriteName(s: String); | ||
| 40 | function ReadName: String; | ||
| 41 | procedure WriteVersion(s: String); | ||
| 42 | function ReadVersion: String; | ||
| 43 | procedure WriteIcon(s: String); | ||
| 44 | function ReadIcon: String; | ||
| 45 | procedure WriteSDesc(s: String); | ||
| 46 | function ReadSDesc: String; | ||
| 47 | procedure WriteCategory(g: AppCategory); | ||
| 48 | function ReadCategory: AppCategory; | ||
| 49 | procedure WriteAuthor(s: String); | ||
| 50 | function ReadAuthor: String; | ||
| 51 | procedure WriteMaintainer(s: String); | ||
| 52 | function ReadMaintainer: String; | ||
| 53 | procedure WriteDisallows(s: String); | ||
| 54 | function ReadDisallows: String; | ||
| 55 | procedure WriteAppCMD(s: String); | ||
| 56 | function ReadAppCMD: String; | ||
| 57 | procedure WriteArchs(s: String); | ||
| 58 | function ReadArchs: String; | ||
| 59 | procedure WritePkgName(s: String); | ||
| 60 | function ReadPkgName: String; | ||
| 61 | procedure WriteIPKName(s: String); | ||
| 62 | function ReadIPKName: String; | ||
| 63 | procedure WriteDSupport(s: String); | ||
| 64 | function ReadDSupport: String; | ||
| 65 | procedure WriteWizImage(s: String); | ||
| 66 | function ReadWizImage: String; | ||
| 67 | procedure WriteBinary(s: String); | ||
| 68 | function ReadBinary: String; | ||
| 69 | procedure WriteUSource(s: String); | ||
| 70 | function ReadUSource: String; | ||
| 71 | procedure WriteDesktopFiles(s: String); | ||
| 72 | function ReadDesktopFiles: String; | ||
| 73 | procedure WriteInTerminal(b: Boolean); | ||
| 74 | function ReadInTerminal: Boolean; | ||
| 75 | protected | ||
| 76 | text: TStringList; | ||
| 77 | FBasePath: String; | ||
| 78 | clang: String; | ||
| 79 | motrans: Boolean; | ||
| 80 | mofile: String; | ||
| 81 | procedure WriteField(Name: String; info: TStrings); | ||
| 82 | procedure ReadField(Name: String; info: TStrings); | ||
| 83 | public | ||
| 84 | constructor Create; | ||
| 85 | destructor Destroy; override; | ||
| 86 | |||
| 87 | property BasePath: String read FBasePath write FBasePath; | ||
| 88 | property SType: TPkgType read ReadType write WriteType; | ||
| 89 | property AppName: String read ReadName write WriteName; | ||
| 90 | property AppVersion: String read ReadVersion write WriteVersion; | ||
| 91 | procedure ReadAppLicense(info: TStringList); | ||
| 92 | procedure WriteAppLicense(path: String); | ||
| 93 | procedure WriteAppLicense(info: TStringList); | ||
| 94 | procedure ReadAppDescription(info: TStringList); | ||
| 95 | procedure WriteAppDescription(path: String); | ||
| 96 | procedure WriteAppDescription(info: TStringList); | ||
| 97 | property Icon: String read ReadIcon write WriteIcon; | ||
| 98 | property LangCode: String read clang write clang; | ||
| 99 | property SDesc: String read ReadSDesc write WriteSDesc; | ||
| 100 | property Category: AppCategory read ReadCategory write WriteCategory; | ||
| 101 | property Author: String read ReadAuthor write WriteAuthor; | ||
| 102 | property Maintainer: String read ReadMaintainer write WriteMaintainer; | ||
| 103 | property Disallows: String read ReadDisallows write WriteDisallows; | ||
| 104 | procedure ReadProfiles(lst: TStrings); | ||
| 105 | procedure WriteProfiles(lst: TStrings); | ||
| 106 | procedure ReadBuildCMDs(lst: TStrings); | ||
| 107 | procedure WriteBuildCMDs(lst: TStrings); | ||
| 108 | property AppCMD: String read ReadAppCMD write WriteAppCMD; | ||
| 109 | property Architecture: String read ReadArchs write WriteArchs; | ||
| 110 | property PkName: String read ReadPkgName write WritePkgName; | ||
| 111 | property IPKName: String read ReadIPKName write WriteIPKName; | ||
| 112 | property DSupport: String read ReadDSupport write WriteDSupport; | ||
| 113 | property WizImage: String read ReadWizImage write WriteWizImage; | ||
| 114 | property Binary: String read ReadBinary write WriteBinary; | ||
| 115 | property USource: String read ReadUSource write WriteUSource; | ||
| 116 | property Desktopfiles: String read ReadDesktopFiles write WriteDesktopFiles; | ||
| 117 | property InTerminal: Boolean read ReadInTerminal write WriteInTerminal; | ||
| 118 | procedure ReadDependencies(dname: String; info: TStringList); | ||
| 119 | procedure WriteDependencies(dname: String; path: String); | ||
| 120 | procedure WriteDependencies(dname: String; info: TStringList); | ||
| 121 | function LoadFromFile(s: String): Boolean; virtual; abstract; | ||
| 122 | property UseMoTranslation: Boolean read motrans write motrans; | ||
| 123 | procedure GetMoFileList(list: TStringList); | ||
| 124 | procedure SetMoFilesToDir(dir: String); | ||
| 125 | end; | ||
| 126 | |||
| 127 | TIPKControl = class; | ||
| 128 | |||
| 129 | //** Class to handle IPK scripts | ||
| 130 | TIPKScript = class(TIPKBasic) | ||
| 131 | private | ||
| 132 | fname: String; | ||
| 133 | public | ||
| 134 | constructor Create; | ||
| 135 | destructor Destroy; override; | ||
| 136 | |||
| 137 | function SaveToFile(s: String): Boolean; | ||
| 138 | function LoadFromFile(s: String): Boolean; override; | ||
| 139 | function LoadFromList(lst: TStrings): Boolean; | ||
| 140 | procedure GetFiles(id: Integer; lst: TStrings); | ||
| 141 | procedure GetDirectFileList(id: Integer; lst: TStrings); | ||
| 142 | function FinalizeToControl: TIPKControl; | ||
| 143 | end; | ||
| 144 | |||
| 145 | //** Class to read IPK control files | ||
| 146 | TIPKControl = class(TIPKBasic) | ||
| 147 | private | ||
| 148 | fname: String; | ||
| 149 | public | ||
| 150 | constructor Create; | ||
| 151 | constructor Create(path: String); | ||
| 152 | destructor Destroy; override; | ||
| 153 | |||
| 154 | function SaveToFile(s: String): Boolean; | ||
| 155 | procedure GetInternalFilesSection(lst: TStrings); | ||
| 156 | function LoadFromFile(s: String): Boolean; override; | ||
| 157 | |||
| 158 | property RawText: TStringList read text write text; | ||
| 159 | end; | ||
| 160 | |||
| 161 | implementation | ||
| 162 | |||
| 163 | { TIPKBasic } | ||
| 164 | |||
| 165 | constructor TIPKBasic.Create; | ||
| 166 | begin | ||
| 167 | inherited; | ||
| 168 | Text := TStringList.Create; | ||
| 169 | FBasePath := ExtractFilePath(ParamStr(0)); | ||
| 170 | clang := ''; | ||
| 171 | mofile := ''; | ||
| 172 | motrans := false; | ||
| 173 | end; | ||
| 174 | |||
| 175 | destructor TIPKBasic.Destroy; | ||
| 176 | begin | ||
| 177 | Text.Free; | ||
| 178 | inherited; | ||
| 179 | end; | ||
| 180 | |||
| 181 | procedure TIPKBasic.WriteEntry(k, s: String); | ||
| 182 | begin | ||
| 183 | s := k + ': ' + s; | ||
| 184 | if SearchKeyIndex(k) > -1 then | ||
| 185 | Text[SearchKeyIndex(k)] := s | ||
| 186 | else | ||
| 187 | Text.Add(s); | ||
| 188 | end; | ||
| 189 | |||
| 190 | function TIPKBasic.GetValue(s: String): String; | ||
| 191 | begin | ||
| 192 | if pos(':', s) = length(s) then | ||
| 193 | begin | ||
| 194 | //There is an empty block (without value) | ||
| 195 | Result := ''; | ||
| 196 | exit; | ||
| 197 | end; | ||
| 198 | Result := copy(s, pos(':', s) + 1, length(s)); | ||
| 199 | if (Result[1] = ' ') then | ||
| 200 | Result := copy(Result, 2, length(Result)); | ||
| 201 | end; | ||
| 202 | |||
| 203 | function TIPKBasic.SearchKeyIndex(S: String; localized: Boolean = true): Integer; | ||
| 204 | var | ||
| 205 | i: Integer; | ||
| 206 | h: String; | ||
| 207 | begin | ||
| 208 | Result := -1; | ||
| 209 | i := Text.Count; | ||
| 210 | //First search for localized entry | ||
| 211 | if (clang <> '') and (localized) then | ||
| 212 | begin | ||
| 213 | for i := 0 to Text.Count - 1 do | ||
| 214 | begin | ||
| 215 | if (length(Text[i])>0)and(Text[i][1]<>'#')and(Text[i][1]<>' ') then | ||
| 216 | begin | ||
| 217 | h := copy(Text[i], 0, pos(':', Text[i]) - 1); | ||
| 218 | if LowerCase(h) = LowerCase(s) + '[' + clang + ']' then | ||
| 219 | begin | ||
| 220 | Result := i; | ||
| 221 | break; | ||
| 222 | end; | ||
| 223 | end; | ||
| 224 | end; | ||
| 225 | end; | ||
| 226 | //Then search the general key | ||
| 227 | if (not localized) or (Result < 0) then | ||
| 228 | for i := 0 to Text.Count - 1 do | ||
| 229 | begin | ||
| 230 | if (length(Text[i])>0)and(Text[i][1]<>'#')and(Text[i][1]<>' ') then | ||
| 231 | begin | ||
| 232 | h := copy(Text[i], 0, pos(':', Text[i]) - 1); | ||
| 233 | if LowerCase(h) = LowerCase(s) then | ||
| 234 | begin | ||
| 235 | Result := i; | ||
| 236 | break; | ||
| 237 | end; | ||
| 238 | end; | ||
| 239 | end; | ||
| 240 | end; | ||
| 241 | |||
| 242 | function TIPKBasic.SolveInclude(s: String): String; | ||
| 243 | var | ||
| 244 | h: String; | ||
| 245 | begin | ||
| 246 | h := copy(s, pos('"', s) + 1, length(s)); | ||
| 247 | h := copy(h, 0, pos('"', h) - 1); | ||
| 248 | if not FilenameIsAbsolute(h) then | ||
| 249 | Result := AppendPathDelim(FBasePath) + h | ||
| 250 | else | ||
| 251 | Result := h; | ||
| 252 | end; | ||
| 253 | |||
| 254 | function TIPKBasic.Translate(s: String): String; | ||
| 255 | var | ||
| 256 | i: Integer; | ||
| 257 | mo: TMoFile; | ||
| 258 | begin | ||
| 259 | Result := s; | ||
| 260 | if mofile = '~' then | ||
| 261 | exit; | ||
| 262 | if mofile = '' then | ||
| 263 | begin | ||
| 264 | mofile := '~'; | ||
| 265 | for i := 0 to text.Count - 1 do | ||
| 266 | if pos('include:', Text[i]) > 0 then | ||
| 267 | if LowerCase(ExtractFileExt(SolveInclude(Text[i]))) = '.mo' then | ||
| 268 | begin | ||
| 269 | mofile := ExtractFileName(SolveInclude(Text[i])); | ||
| 270 | if (mofile = GetLangId + '.mo') or | ||
| 271 | (copy(mofile, pos('-', mofile) + 1, length(mofile)) = GetlangId + '.mo') then | ||
| 272 | break | ||
| 273 | else | ||
| 274 | mofile := '~'; | ||
| 275 | end; | ||
| 276 | end; | ||
| 277 | if (mofile = '~') or (trim(mofile) = '') or (not FileExists(FBasePath+mofile)) then | ||
| 278 | exit; | ||
| 279 | mo := TMoFile.Create(FBasePath+mofile); | ||
| 280 | Result := mo.Translate(s); | ||
| 281 | mo.Free; | ||
| 282 | end; | ||
| 283 | |||
| 284 | procedure TIPKBasic.GetMoFileList(list: TStringList); | ||
| 285 | var | ||
| 286 | i: Integer; | ||
| 287 | begin | ||
| 288 | for i := 0 to Text.Count - 1 do | ||
| 289 | if pos('include:', Text[i]) > 0 then | ||
| 290 | begin | ||
| 291 | if (ExtractFileExt(SolveInclude(text[i]))) = '.mo' then | ||
| 292 | list.Add(SolveInclude(text[i])); | ||
| 293 | end; | ||
| 294 | end; | ||
| 295 | |||
| 296 | procedure TIPKBasic.SetMoFilesToDir(dir: String); | ||
| 297 | var | ||
| 298 | list: TStringList; | ||
| 299 | i: Integer; | ||
| 300 | begin | ||
| 301 | list := TStringList.Create; | ||
| 302 | GetMoFileList(list); | ||
| 303 | i := 0; | ||
| 304 | while i < text.Count do | ||
| 305 | begin | ||
| 306 | if (pos('include:', text[i])>0) and(pos('.mo', text[i])>0) then | ||
| 307 | begin | ||
| 308 | text.Delete(i); | ||
| 309 | end | ||
| 310 | else | ||
| 311 | Inc(i); | ||
| 312 | end; | ||
| 313 | text.Insert(1, ''); | ||
| 314 | for i := 0 to list.Count-1 do | ||
| 315 | text.Insert(1, 'include:"'+dir+'/'+ExtractFileName(list[i])+'"'); | ||
| 316 | list.Free; | ||
| 317 | end; | ||
| 318 | |||
| 319 | procedure TIPKBasic.WriteField(Name: String; info: TStrings); | ||
| 320 | var | ||
| 321 | i: Integer; | ||
| 322 | begin | ||
| 323 | if info.Count >= 0 then | ||
| 324 | begin | ||
| 325 | i := SearchKeyIndex(Name); | ||
| 326 | if i > 0 then | ||
| 327 | begin | ||
| 328 | |||
| 329 | Text.Delete(i); | ||
| 330 | while (i < Text.Count) and (Text[i] <> '') and (Text[i][1] = ' ') do | ||
| 331 | Text.Delete(i); | ||
| 332 | end; | ||
| 333 | |||
| 334 | Text.Add(Name + ': ' + info[0]); | ||
| 335 | for i := 1 to info.Count - 1 do | ||
| 336 | Text.Add(' ' + info[i]); | ||
| 337 | end; | ||
| 338 | end; | ||
| 339 | |||
| 340 | procedure TIPKBasic.ReadField(Name: String; info: TStrings); | ||
| 341 | var | ||
| 342 | i: Integer; | ||
| 343 | s: String; | ||
| 344 | begin | ||
| 345 | i := SearchKeyIndex(Name); | ||
| 346 | s := ''; | ||
| 347 | if i > -1 then | ||
| 348 | s := Text[i]; | ||
| 349 | info.Clear; | ||
| 350 | if s = '' then | ||
| 351 | exit; | ||
| 352 | if pos('include:"', s) > 0 then | ||
| 353 | info.LoadFromFile(SolveInclude(s)) | ||
| 354 | else | ||
| 355 | begin | ||
| 356 | info.Add(GetValue(Text[i])); | ||
| 357 | Inc(i); | ||
| 358 | if i < Text.Count then | ||
| 359 | repeat | ||
| 360 | s := Text[i]; | ||
| 361 | if s[1] = ' ' then | ||
| 362 | begin | ||
| 363 | s := copy(s, 2, length(s)); | ||
| 364 | info.Add(s); | ||
| 365 | end; | ||
| 366 | Inc(i); | ||
| 367 | until (i >= Text.Count) or (Text[i][1] <> ' ') or (length(Text[i]) < 1); | ||
| 368 | end; | ||
| 369 | end; | ||
| 370 | |||
| 371 | procedure TIPKBasic.WriteType(atype: TPkgType); | ||
| 372 | var | ||
| 373 | h: String; | ||
| 374 | begin | ||
| 375 | case AType of | ||
| 376 | ptLinstall: h := 'Type: linstall'; | ||
| 377 | ptDLink: h := 'Type: dlink'; | ||
| 378 | ptContainer: h := 'Type: container'; | ||
| 379 | end; | ||
| 380 | if SearchKeyIndex('Type', false) > -1 then | ||
| 381 | Text[SearchKeyIndex('Type', false)] := h | ||
| 382 | else | ||
| 383 | Text.Add(h); | ||
| 384 | end; | ||
| 385 | |||
| 386 | function TIPKBasic.ReadType: TPkgType; | ||
| 387 | var | ||
| 388 | s: String; | ||
| 389 | j: Integer; | ||
| 390 | begin | ||
| 391 | Result := ptUnknown; | ||
| 392 | j := SearchKeyIndex('Type', false); | ||
| 393 | |||
| 394 | if j > -1 then | ||
| 395 | begin | ||
| 396 | s := Text[j]; | ||
| 397 | writeLn(s); | ||
| 398 | if GetValue(s) = 'linstall' then | ||
| 399 | Result := ptLinstall; | ||
| 400 | if GetValue(s) = 'dlink' then | ||
| 401 | Result := ptDLink; | ||
| 402 | if GetValue(s) = 'container' then | ||
| 403 | Result := ptContainer; | ||
| 404 | end; | ||
| 405 | end; | ||
| 406 | |||
| 407 | procedure TIPKBasic.WriteName(s: String); | ||
| 408 | var | ||
| 409 | k: String; | ||
| 410 | begin | ||
| 411 | if clang = '' then | ||
| 412 | k := 'Name' | ||
| 413 | else | ||
| 414 | k := 'Name[' + clang + ']'; | ||
| 415 | |||
| 416 | WriteEntry(k, s); | ||
| 417 | end; | ||
| 418 | |||
| 419 | function TIPKBasic.ReadName: String; | ||
| 420 | var | ||
| 421 | j: Integer; | ||
| 422 | begin | ||
| 423 | Result := ''; | ||
| 424 | j := SearchKeyIndex('Name'); | ||
| 425 | if j > -1 then | ||
| 426 | Result := GetValue(Text[j]); | ||
| 427 | Result := translate(Result); | ||
| 428 | end; | ||
| 429 | |||
| 430 | procedure TIPKBasic.WriteVersion(s: String); | ||
| 431 | var | ||
| 432 | k: String; | ||
| 433 | begin | ||
| 434 | if clang = '' then | ||
| 435 | k := 'Version' | ||
| 436 | else | ||
| 437 | k := 'Version[' + clang + ']'; | ||
| 438 | |||
| 439 | WriteEntry(k, s); | ||
| 440 | end; | ||
| 441 | |||
| 442 | function TIPKBasic.ReadVersion: String; | ||
| 443 | var | ||
| 444 | j: Integer; | ||
| 445 | begin | ||
| 446 | Result := ''; | ||
| 447 | j := SearchKeyIndex('Version'); | ||
| 448 | if j > -1 then | ||
| 449 | Result := GetValue(Text[j]); | ||
| 450 | end; | ||
| 451 | |||
| 452 | procedure TIPKBasic.ReadAppLicense(info: TStringList); | ||
| 453 | begin | ||
| 454 | ReadField('License', info); | ||
| 455 | end; | ||
| 456 | |||
| 457 | procedure TIPKBasic.WriteAppLicense(path: String); | ||
| 458 | var | ||
| 459 | s: String; | ||
| 460 | i: Integer; | ||
| 461 | begin | ||
| 462 | s := 'License: include:"' + path + '"'; | ||
| 463 | |||
| 464 | i := SearchKeyIndex('License'); | ||
| 465 | if i > 0 then | ||
| 466 | begin | ||
| 467 | Text.Delete(i); | ||
| 468 | while (i < Text.Count) and (Text[i][1] = ' ') do | ||
| 469 | Text.Delete(i); | ||
| 470 | end; | ||
| 471 | |||
| 472 | if i > -1 then | ||
| 473 | Text[i] := s | ||
| 474 | else | ||
| 475 | Text.Add(s); | ||
| 476 | end; | ||
| 477 | |||
| 478 | procedure TIPKBasic.WriteAppLicense(info: TStringList); | ||
| 479 | begin | ||
| 480 | WriteField('License', info); | ||
| 481 | end; | ||
| 482 | |||
| 483 | procedure TIPKBasic.ReadAppDescription(info: TStringList); | ||
| 484 | begin | ||
| 485 | ReadField('Description', info); | ||
| 486 | end; | ||
| 487 | |||
| 488 | procedure TIPKBasic.WriteAppDescription(path: String); | ||
| 489 | var | ||
| 490 | s: String; | ||
| 491 | i: Integer; | ||
| 492 | begin | ||
| 493 | s := 'Description: include:"' + path + '"'; | ||
| 494 | |||
| 495 | i := SearchKeyIndex('Description'); | ||
| 496 | if i > 0 then | ||
| 497 | begin | ||
| 498 | Text.Delete(i); | ||
| 499 | while (i < Text.Count) and (Text[i][1] = ' ') do | ||
| 500 | Text.Delete(i); | ||
| 501 | end; | ||
| 502 | |||
| 503 | if i > -1 then | ||
| 504 | Text[i] := s | ||
| 505 | else | ||
| 506 | Text.Add(s); | ||
| 507 | end; | ||
| 508 | |||
| 509 | procedure TIPKBasic.WriteAppDescription(info: TStringList); | ||
| 510 | begin | ||
| 511 | WriteField('Description', info); | ||
| 512 | end; | ||
| 513 | |||
| 514 | procedure TIPKBasic.WriteIcon(s: String); | ||
| 515 | begin | ||
| 516 | WriteEntry('Icon', s); | ||
| 517 | end; | ||
| 518 | |||
| 519 | function TIPKBasic.ReadIcon: String; | ||
| 520 | var | ||
| 521 | j: Integer; | ||
| 522 | begin | ||
| 523 | Result := ''; | ||
| 524 | j := SearchKeyIndex('Icon', false); | ||
| 525 | if j > -1 then | ||
| 526 | Result := GetValue(Text[j]); | ||
| 527 | end; | ||
| 528 | |||
| 529 | procedure TIPKBasic.WriteSDesc(s: String); | ||
| 530 | var | ||
| 531 | k: String; | ||
| 532 | begin | ||
| 533 | if clang = '' then | ||
| 534 | k := 'SDesc' | ||
| 535 | else | ||
| 536 | k := 'SDesc[' + clang + ']'; | ||
| 537 | |||
| 538 | WriteEntry(k, s); | ||
| 539 | end; | ||
| 540 | |||
| 541 | function TIPKBasic.ReadSDesc: String; | ||
| 542 | var | ||
| 543 | j: Integer; | ||
| 544 | begin | ||
| 545 | Result := ''; | ||
| 546 | j := SearchKeyIndex('SDesc'); | ||
| 547 | if j > -1 then | ||
| 548 | Result := GetValue(Text[j]); | ||
| 549 | |||
| 550 | Result := translate(Result); | ||
| 551 | end; | ||
| 552 | |||
| 553 | procedure TIPKBasic.WriteCategory(g: AppCategory); | ||
| 554 | var | ||
| 555 | s: String; | ||
| 556 | begin | ||
| 557 | case g of | ||
| 558 | gtALL: s := 'All'; | ||
| 559 | gtEDUCATION: s := 'Education'; | ||
| 560 | gtOFFICE: s := 'Office'; | ||
| 561 | gtDEVELOPMENT: s := 'Development'; | ||
| 562 | gtGRAPHIC: s := 'Graphic'; | ||
| 563 | gtNETWORK: s := 'Network'; | ||
| 564 | gtGAMES: s := 'Games'; | ||
| 565 | gtSYSTEM: s := 'System'; | ||
| 566 | gtMULTIMEDIA: s := 'Multimedia'; | ||
| 567 | gtADDITIONAL: s := 'Additional'; | ||
| 568 | gtOTHER: s := 'Other'; | ||
| 569 | end; | ||
| 570 | s := 'Group: ' + s; | ||
| 571 | |||
| 572 | if SearchKeyIndex('Group', false) > -1 then | ||
| 573 | Text[SearchKeyIndex('Group', false)] := s | ||
| 574 | else | ||
| 575 | Text.Add(s); | ||
| 576 | end; | ||
| 577 | |||
| 578 | function TIPKBasic.ReadCategory: AppCategory; | ||
| 579 | var | ||
| 580 | j: Integer; | ||
| 581 | s: String; | ||
| 582 | begin | ||
| 583 | Result := gtUNKNOWN; | ||
| 584 | j := SearchKeyIndex('Group', false); | ||
| 585 | if j > -1 then | ||
| 586 | s := GetValue(Text[j]); | ||
| 587 | |||
| 588 | s := LowerCase(s); | ||
| 589 | if s = 'all' then | ||
| 590 | Result := gtALL; | ||
| 591 | if s = 'education' then | ||
| 592 | Result := gtEDUCATION; | ||
| 593 | if s = 'office' then | ||
| 594 | Result := gtOFFICE; | ||
| 595 | if s = 'development' then | ||
| 596 | Result := gtDEVELOPMENT; | ||
| 597 | if s = 'graphic' then | ||
| 598 | Result := gtGRAPHIC; | ||
| 599 | if s = 'network' then | ||
| 600 | Result := gtNETWORK; | ||
| 601 | if s = 'games' then | ||
| 602 | Result := gtGAMES; | ||
| 603 | if s = 'system' then | ||
| 604 | Result := gtSYSTEM; | ||
| 605 | if s = 'multimedia' then | ||
| 606 | Result := gtMULTIMEDIA; | ||
| 607 | if s = 'additional' then | ||
| 608 | Result := gtADDITIONAL; | ||
| 609 | if s = 'other' then | ||
| 610 | Result := gtOTHER; | ||
| 611 | end; | ||
| 612 | |||
| 613 | procedure TIPKBasic.ReadBuildCMDs(lst: TStrings); | ||
| 614 | begin | ||
| 615 | ReadField('Build', lst); | ||
| 616 | end; | ||
| 617 | |||
| 618 | procedure TIPKBasic.WriteBuildCMDs(lst: TStrings); | ||
| 619 | begin | ||
| 620 | WriteField('Build', lst); | ||
| 621 | end; | ||
| 622 | |||
| 623 | procedure TIPKBasic.WriteAuthor(s: String); | ||
| 624 | var | ||
| 625 | k: String; | ||
| 626 | begin | ||
| 627 | if clang = '' then | ||
| 628 | k := 'Author' | ||
| 629 | else | ||
| 630 | k := 'Author[' + clang + ']'; | ||
| 631 | |||
| 632 | WriteEntry(k, s); | ||
| 633 | end; | ||
| 634 | |||
| 635 | function TIPKBasic.ReadAuthor: String; | ||
| 636 | var | ||
| 637 | j: Integer; | ||
| 638 | begin | ||
| 639 | Result := ''; | ||
| 640 | j := SearchKeyIndex('Author'); | ||
| 641 | if j > -1 then | ||
| 642 | Result := GetValue(Text[j]); | ||
| 643 | Result := translate(Result); | ||
| 644 | end; | ||
| 645 | |||
| 646 | procedure TIPKBasic.WriteMaintainer(s: String); | ||
| 647 | var | ||
| 648 | k: String; | ||
| 649 | begin | ||
| 650 | if clang = '' then | ||
| 651 | k := 'Maintainer' | ||
| 652 | else | ||
| 653 | k := 'Maintainer[' + clang + ']'; | ||
| 654 | |||
| 655 | WriteEntry(k, s); | ||
| 656 | end; | ||
| 657 | |||
| 658 | function TIPKBasic.ReadMaintainer: String; | ||
| 659 | var | ||
| 660 | j: Integer; | ||
| 661 | begin | ||
| 662 | Result := ''; | ||
| 663 | j := SearchKeyIndex('Maintainer'); | ||
| 664 | if j > -1 then | ||
| 665 | Result := GetValue(Text[j]); | ||
| 666 | Result := translate(Result); | ||
| 667 | end; | ||
| 668 | |||
| 669 | procedure TIPKBasic.WriteDisallows(s: String); | ||
| 670 | var | ||
| 671 | k: String; | ||
| 672 | begin | ||
| 673 | k := 'Disallow'; | ||
| 674 | WriteEntry(k, s); | ||
| 675 | end; | ||
| 676 | |||
| 677 | function TIPKBasic.ReadDisallows: String; | ||
| 678 | var | ||
| 679 | j: Integer; | ||
| 680 | begin | ||
| 681 | Result := ''; | ||
| 682 | j := SearchKeyIndex('Disallow', false); | ||
| 683 | if j > -1 then | ||
| 684 | Result := GetValue(Text[j]); | ||
| 685 | end; | ||
| 686 | |||
| 687 | procedure TIPKBasic.WriteProfiles(lst: TStrings); | ||
| 688 | var | ||
| 689 | k, s: String; | ||
| 690 | i: Integer; | ||
| 691 | begin | ||
| 692 | k := 'Profile['; | ||
| 693 | for i := 0 to lst.Count - 1 do | ||
| 694 | begin | ||
| 695 | s := k + IntToStr(i) + ']: ' + lst[i]; | ||
| 696 | if SearchKeyIndex(k) > -1 then | ||
| 697 | Text[SearchKeyIndex(k)] := s | ||
| 698 | else | ||
| 699 | Text.Add(s); | ||
| 700 | end; | ||
| 701 | end; | ||
| 702 | |||
| 703 | procedure TIPKBasic.ReadProfiles(lst: TStrings); | ||
| 704 | var | ||
| 705 | j: Integer; | ||
| 706 | |||
| 707 | function GetProfileName(id: Integer): String; | ||
| 708 | var | ||
| 709 | i: Integer; | ||
| 710 | begin | ||
| 711 | Result := ''; | ||
| 712 | i := SearchKeyIndex('Profiles[' + IntToStr(id) + ']'); | ||
| 713 | if (id = 0) and (i < 0) then | ||
| 714 | i := SearchKeyIndex('Profiles'); | ||
| 715 | if i > -1 then | ||
| 716 | Result := GetValue(Text[i]); | ||
| 717 | end; | ||
| 718 | |||
| 719 | begin | ||
| 720 | j := 0; | ||
| 721 | repeat | ||
| 722 | lst.Add(GetProfileName(j)); | ||
| 723 | Inc(j); | ||
| 724 | until GetProfileName(j) = ''; | ||
| 725 | end; | ||
| 726 | |||
| 727 | procedure TIPKBasic.WriteAppCMD(s: String); | ||
| 728 | var | ||
| 729 | k: String; | ||
| 730 | begin | ||
| 731 | k := 'AppCMD'; | ||
| 732 | |||
| 733 | WriteEntry(k, s); | ||
| 734 | end; | ||
| 735 | |||
| 736 | function TIPKBasic.ReadAppCMD: String; | ||
| 737 | var | ||
| 738 | j: Integer; | ||
| 739 | begin | ||
| 740 | Result := ''; | ||
| 741 | j := SearchKeyIndex('AppCMD', false); | ||
| 742 | if j > -1 then | ||
| 743 | Result := GetValue(Text[j]); | ||
| 744 | end; | ||
| 745 | |||
| 746 | procedure TIPKBasic.WriteArchs(s: String); | ||
| 747 | var | ||
| 748 | k: String; | ||
| 749 | begin | ||
| 750 | k := 'Architecture'; | ||
| 751 | WriteEntry(k, s); | ||
| 752 | end; | ||
| 753 | |||
| 754 | function TIPKBasic.ReadArchs: String; | ||
| 755 | var | ||
| 756 | j: Integer; | ||
| 757 | begin | ||
| 758 | Result := ''; | ||
| 759 | j := SearchKeyIndex('Architecture', false); | ||
| 760 | if j > -1 then | ||
| 761 | Result := GetValue(Text[j]); | ||
| 762 | end; | ||
| 763 | |||
| 764 | procedure TIPKBasic.WritePkgName(s: String); | ||
| 765 | var | ||
| 766 | k: String; | ||
| 767 | begin | ||
| 768 | k := 'PkName'; | ||
| 769 | WriteEntry(k, s); | ||
| 770 | end; | ||
| 771 | |||
| 772 | function TIPKBasic.ReadPkgName: String; | ||
| 773 | var | ||
| 774 | j: Integer; | ||
| 775 | begin | ||
| 776 | Result := ''; | ||
| 777 | j := SearchKeyIndex('PkName', false); | ||
| 778 | if j > -1 then | ||
| 779 | Result := GetValue(Text[j]); | ||
| 780 | end; | ||
| 781 | |||
| 782 | procedure TIPKBasic.WriteIPKName(s: String); | ||
| 783 | var | ||
| 784 | k: String; | ||
| 785 | begin | ||
| 786 | k := 'IPKName'; | ||
| 787 | WriteEntry(k, s); | ||
| 788 | end; | ||
| 789 | |||
| 790 | function TIPKBasic.ReadIPKName: String; | ||
| 791 | var | ||
| 792 | j: Integer; | ||
| 793 | begin | ||
| 794 | Result := ''; | ||
| 795 | j := SearchKeyIndex('IPKName', false); | ||
| 796 | if j > -1 then | ||
| 797 | Result := GetValue(Text[j]); | ||
| 798 | end; | ||
| 799 | |||
| 800 | procedure TIPKBasic.WriteDSupport(s: String); | ||
| 801 | var | ||
| 802 | k: String; | ||
| 803 | begin | ||
| 804 | k := 'DSupport'; | ||
| 805 | WriteEntry(k, s); | ||
| 806 | end; | ||
| 807 | |||
| 808 | function TIPKBasic.ReadDSupport: String; | ||
| 809 | var | ||
| 810 | j: Integer; | ||
| 811 | begin | ||
| 812 | Result := ''; | ||
| 813 | j := SearchKeyIndex('DSupport', false); | ||
| 814 | if j > -1 then | ||
| 815 | Result := GetValue(Text[j]); | ||
| 816 | end; | ||
| 817 | |||
| 818 | procedure TIPKBasic.ReadDependencies(dname: String; info: TStringList); | ||
| 819 | var | ||
| 820 | i: Integer; | ||
| 821 | s: String; | ||
| 822 | begin | ||
| 823 | if (dname = 'all') or (dname = '') then | ||
| 824 | i := SearchKeyIndex('Dependencies', false) | ||
| 825 | else | ||
| 826 | i := SearchKeyIndex('Dependencies[' + dname + ']', false); | ||
| 827 | |||
| 828 | s := ''; | ||
| 829 | if i > -1 then | ||
| 830 | s := Text[i]; | ||
| 831 | info.Clear; | ||
| 832 | |||
| 833 | if s = '' then | ||
| 834 | exit; | ||
| 835 | if pos('include:"', s) > 0 then | ||
| 836 | info.LoadFromFile(SolveInclude(s)) | ||
| 837 | else | ||
| 838 | begin | ||
| 839 | info.Add(GetValue(Text[i])); | ||
| 840 | Inc(i); | ||
| 841 | repeat | ||
| 842 | s := Text[i]; | ||
| 843 | if length(s) > 0 then | ||
| 844 | if s[1] = ' ' then | ||
| 845 | begin | ||
| 846 | s := copy(s, 2, length(s)); | ||
| 847 | info.Add(s); | ||
| 848 | end; | ||
| 849 | Inc(i); | ||
| 850 | until (length(Text[i]) = 0) or (i >= Text.Count) or (Text[i][1] <> ' '); | ||
| 851 | end; | ||
| 852 | end; | ||
| 853 | |||
| 854 | procedure TIPKBasic.WriteDependencies(dname: String; path: String); | ||
| 855 | var | ||
| 856 | s: String; | ||
| 857 | i: Integer; | ||
| 858 | begin | ||
| 859 | if (dname = 'all') or (dname = '') then | ||
| 860 | s := 'Dependencies: include:"' + path + '"' | ||
| 861 | else | ||
| 862 | s := 'Dependencies[' + dname + ']: include:"' + path + '"'; | ||
| 863 | |||
| 864 | i := SearchKeyIndex('Dependencies'); | ||
| 865 | if i > 0 then | ||
| 866 | begin | ||
| 867 | Text.Delete(i); | ||
| 868 | while (i < Text.Count) and (Text[i][1] = ' ') do | ||
| 869 | Text.Delete(i); | ||
| 870 | end; | ||
| 871 | |||
| 872 | if i > -1 then | ||
| 873 | Text[i] := s | ||
| 874 | else | ||
| 875 | Text.Add(s); | ||
| 876 | end; | ||
| 877 | |||
| 878 | procedure TIPKBasic.WriteDependencies(dname: String; info: TStringList); | ||
| 879 | var | ||
| 880 | i: Integer; | ||
| 881 | s: String; | ||
| 882 | begin | ||
| 883 | if info.Count >= 0 then | ||
| 884 | begin | ||
| 885 | if (dname = 'all') or (dname = '') then | ||
| 886 | begin | ||
| 887 | s := 'Dependencies'; | ||
| 888 | i := SearchKeyIndex(s, false); | ||
| 889 | end | ||
| 890 | else | ||
| 891 | begin | ||
| 892 | s := 'Dependencies[' + dname + ']'; | ||
| 893 | i := SearchKeyIndex(s, false); | ||
| 894 | end; | ||
| 895 | |||
| 896 | if i > 0 then | ||
| 897 | begin | ||
| 898 | |||
| 899 | Text.Delete(i); | ||
| 900 | while (i < Text.Count) and (Text[i] <> '') and (Text[i][1] = ' ') do | ||
| 901 | Text.Delete(i); | ||
| 902 | end; | ||
| 903 | |||
| 904 | Text.Add(s + ': ' + info[0]); | ||
| 905 | for i := 1 to info.Count - 1 do | ||
| 906 | Text.Add(' ' + info[i]); | ||
| 907 | |||
| 908 | end; | ||
| 909 | end; | ||
| 910 | |||
| 911 | procedure TIPKBasic.WriteWizImage(s: String); | ||
| 912 | var | ||
| 913 | k: String; | ||
| 914 | begin | ||
| 915 | k := 'WizImage'; | ||
| 916 | WriteEntry(k, s); | ||
| 917 | end; | ||
| 918 | |||
| 919 | function TIPKBasic.ReadWizImage: String; | ||
| 920 | var | ||
| 921 | j: Integer; | ||
| 922 | begin | ||
| 923 | Result := ''; | ||
| 924 | j := SearchKeyIndex('WizImage', false); | ||
| 925 | if j > -1 then | ||
| 926 | Result := GetValue(Text[j]); | ||
| 927 | end; | ||
| 928 | |||
| 929 | procedure TIPKBasic.WriteBinary(s: String); | ||
| 930 | begin | ||
| 931 | WriteEntry('Binary', s); | ||
| 932 | end; | ||
| 933 | |||
| 934 | function TIPKBasic.ReadBinary: String; | ||
| 935 | var | ||
| 936 | j: Integer; | ||
| 937 | begin | ||
| 938 | Result := ''; | ||
| 939 | j := SearchKeyIndex('Binary', false); | ||
| 940 | if j > -1 then | ||
| 941 | Result := GetValue(Text[j]); | ||
| 942 | end; | ||
| 943 | |||
| 944 | procedure TIPKBasic.WriteUSource(s: String); | ||
| 945 | begin | ||
| 946 | WriteEntry('USource', s); | ||
| 947 | end; | ||
| 948 | |||
| 949 | function TIPKBasic.ReadUSource: String; | ||
| 950 | var | ||
| 951 | j: Integer; | ||
| 952 | begin | ||
| 953 | Result := ''; | ||
| 954 | j := SearchKeyIndex('USource', false); | ||
| 955 | if j > -1 then | ||
| 956 | Result := GetValue(Text[j]); | ||
| 957 | end; | ||
| 958 | |||
| 959 | procedure TIPKBasic.WriteDesktopFiles(s: String); | ||
| 960 | begin | ||
| 961 | WriteEntry('Desktopfiles', s); | ||
| 962 | end; | ||
| 963 | |||
| 964 | function TIPKBasic.ReadDesktopFiles: String; | ||
| 965 | var | ||
| 966 | j: Integer; | ||
| 967 | begin | ||
| 968 | Result := ''; | ||
| 969 | j := SearchKeyIndex('Desktopfiles', false); | ||
| 970 | if j > -1 then | ||
| 971 | Result := GetValue(Text[j]); | ||
| 972 | end; | ||
| 973 | |||
| 974 | procedure TIPKBasic.WriteInTerminal(b: Boolean); | ||
| 975 | begin | ||
| 976 | if b = true then | ||
| 977 | WriteEntry('Desktopfiles', 'true') | ||
| 978 | else | ||
| 979 | WriteEntry('Desktopfiles', 'false'); | ||
| 980 | end; | ||
| 981 | |||
| 982 | function TIPKBasic.ReadInTerminal: Boolean; | ||
| 983 | var | ||
| 984 | j: Integer; | ||
| 985 | s: String; | ||
| 986 | begin | ||
| 987 | j := SearchKeyIndex('InTerminal', false); | ||
| 988 | if j > -1 then | ||
| 989 | s := GetValue(Text[j]); | ||
| 990 | if LowerCase(s) = 'true' then | ||
| 991 | Result := true | ||
| 992 | else | ||
| 993 | Result := false; | ||
| 994 | end; | ||
| 995 | |||
| 996 | { TIPKScript } | ||
| 997 | |||
| 998 | constructor TIPKScript.Create; | ||
| 999 | begin | ||
| 1000 | inherited; | ||
| 1001 | Text.Add('IPK-Standard-Version: 1.1'); | ||
| 1002 | Text.Add(''); | ||
| 1003 | fname := ''; | ||
| 1004 | end; | ||
| 1005 | |||
| 1006 | destructor TIPKScript.Destroy; | ||
| 1007 | begin | ||
| 1008 | inherited; | ||
| 1009 | end; | ||
| 1010 | |||
| 1011 | function TIPKScript.SaveToFile(s: String): Boolean; | ||
| 1012 | begin | ||
| 1013 | Result := true; | ||
| 1014 | try | ||
| 1015 | Text.SaveTofile(s); | ||
| 1016 | FBasePath := ExtractFilePath(s); | ||
| 1017 | fname := s; | ||
| 1018 | except | ||
| 1019 | Result := false; | ||
| 1020 | end; | ||
| 1021 | end; | ||
| 1022 | |||
| 1023 | function TIPKScript.LoadFromFile(s: String): Boolean; | ||
| 1024 | begin | ||
| 1025 | Result := true; | ||
| 1026 | if FileExists(s) then | ||
| 1027 | begin | ||
| 1028 | Text.LoadFromFile(s); | ||
| 1029 | if (Text[0] <> 'IPK-Standard-Version: 1.1') | ||
| 1030 | and(Text[0] <> 'IPK-Standard-Version: 1.0') then | ||
| 1031 | begin | ||
| 1032 | Result := false; | ||
| 1033 | Text.Clear; | ||
| 1034 | Text.Add('IPK-Standard-Version: 1.1'); | ||
| 1035 | Text.Add(''); | ||
| 1036 | exit; | ||
| 1037 | end; | ||
| 1038 | FBasePath := ExtractFilePath(s); | ||
| 1039 | fname := s; | ||
| 1040 | end | ||
| 1041 | else | ||
| 1042 | Result := false; | ||
| 1043 | end; | ||
| 1044 | |||
| 1045 | function TIPKScript.LoadFromList(lst: TStrings): Boolean; | ||
| 1046 | begin | ||
| 1047 | Result := true; | ||
| 1048 | writeLn(lst[0]); | ||
| 1049 | if (lst[0] <> 'IPK-Standard-Version: 1.1') | ||
| 1050 | and(lst[0] <> 'IPK-Standard-Version: 1.0') then | ||
| 1051 | begin | ||
| 1052 | Result := false; | ||
| 1053 | exit; | ||
| 1054 | end | ||
| 1055 | else | ||
| 1056 | Text.Assign(lst); | ||
| 1057 | end; | ||
| 1058 | |||
| 1059 | function TIPKScript.FinalizeToControl: TIPKControl; | ||
| 1060 | var | ||
| 1061 | i: Integer; | ||
| 1062 | cont: TIPKControl; | ||
| 1063 | |||
| 1064 | procedure ProcessLine(ln: String); | ||
| 1065 | begin | ||
| 1066 | if length(ln) > 0 then | ||
| 1067 | begin | ||
| 1068 | if ln[1] = '#' then | ||
| 1069 | exit; | ||
| 1070 | end; | ||
| 1071 | |||
| 1072 | if pos('#', ln) > 0 then | ||
| 1073 | ln := copy(ln, pos('#', ln) + 1, length(ln)); | ||
| 1074 | |||
| 1075 | if pos('IPKName:', ln) > 0 then | ||
| 1076 | exit; | ||
| 1077 | |||
| 1078 | cont.RawText.Add(ln); | ||
| 1079 | end; | ||
| 1080 | |||
| 1081 | begin | ||
| 1082 | cont := TIPKControl.Create; | ||
| 1083 | |||
| 1084 | for i := 0 to Text.Count - 1 do | ||
| 1085 | if pos('!-Files', Text[i]) <= 0 then | ||
| 1086 | ProcessLine(Text[i]); | ||
| 1087 | |||
| 1088 | Result := cont; | ||
| 1089 | end; | ||
| 1090 | |||
| 1091 | procedure TIPKScript.GetDirectFileList(id: Integer; lst: TStrings); | ||
| 1092 | var | ||
| 1093 | i, j: Integer; | ||
| 1094 | s: String; | ||
| 1095 | fsec: TStringList; | ||
| 1096 | begin | ||
| 1097 | fsec := TStringList.Create; | ||
| 1098 | for j := 0 to Text.Count - 1 do | ||
| 1099 | if pos('!-Files ~' + IntToStr(id), Text[j]) > 0 then | ||
| 1100 | break; | ||
| 1101 | |||
| 1102 | for i := j + 1 to Text.Count - 1 do | ||
| 1103 | if pos('!-Files ~', Text[i]) > 0 then | ||
| 1104 | break | ||
| 1105 | else | ||
| 1106 | fsec.Add(Text[i]); | ||
| 1107 | |||
| 1108 | i := 0; | ||
| 1109 | while i < fsec.Count - 1 do | ||
| 1110 | begin | ||
| 1111 | |||
| 1112 | if fsec[i][1] = '>' then | ||
| 1113 | s := copy(fsec[i], 2, length(fsec[i])) | ||
| 1114 | else | ||
| 1115 | begin | ||
| 1116 | if (fsec[i][1] = '/') or (fsec[i][1] = '.') then | ||
| 1117 | begin | ||
| 1118 | lst.Add(s); | ||
| 1119 | if fsec[i][1] = '.' then | ||
| 1120 | lst.Add(FBasePath + fsec[i]) | ||
| 1121 | else | ||
| 1122 | lst.Add(fsec[i]); | ||
| 1123 | end; | ||
| 1124 | end; | ||
| 1125 | Inc(i); | ||
| 1126 | end; | ||
| 1127 | end; | ||
| 1128 | |||
| 1129 | procedure TIPKScript.GetFiles(id: Integer; lst: TStrings); | ||
| 1130 | var | ||
| 1131 | i, j: Integer; | ||
| 1132 | begin | ||
| 1133 | //Search for container-IPK files section | ||
| 1134 | j := SearchKeyIndex('Files'); | ||
| 1135 | if j > -1 then | ||
| 1136 | begin | ||
| 1137 | ReadField('Files', lst); | ||
| 1138 | end | ||
| 1139 | else | ||
| 1140 | begin | ||
| 1141 | //Read normal files section | ||
| 1142 | for j := 0 to Text.Count - 1 do | ||
| 1143 | if pos('!-Files ~' + IntToStr(id), Text[j]) > 0 then | ||
| 1144 | break; | ||
| 1145 | |||
| 1146 | for i := j + 1 to Text.Count - 1 do | ||
| 1147 | if pos('!-Files ~', Text[i]) > 0 then | ||
| 1148 | break | ||
| 1149 | else | ||
| 1150 | lst.Add(Text[i]); | ||
| 1151 | end; | ||
| 1152 | end; | ||
| 1153 | |||
| 1154 | { TIPKControl } | ||
| 1155 | |||
| 1156 | constructor TIPKControl.Create(path: String); | ||
| 1157 | begin | ||
| 1158 | inherited Create; | ||
| 1159 | |||
| 1160 | LoadFromFile(path); | ||
| 1161 | FBasePath := ExtractFilePath(path); | ||
| 1162 | |||
| 1163 | fname := path; | ||
| 1164 | end; | ||
| 1165 | |||
| 1166 | constructor TIPKControl.Create; | ||
| 1167 | begin | ||
| 1168 | inherited Create; | ||
| 1169 | fname := ''; | ||
| 1170 | FBasePath := ''; | ||
| 1171 | end; | ||
| 1172 | |||
| 1173 | destructor TIPKControl.Destroy; | ||
| 1174 | begin | ||
| 1175 | inherited; | ||
| 1176 | end; | ||
| 1177 | |||
| 1178 | function TIPKControl.SaveToFile(s: String): Boolean; | ||
| 1179 | begin | ||
| 1180 | Result := true; | ||
| 1181 | try | ||
| 1182 | Text.SaveTofile(s); | ||
| 1183 | FBasePath := ExtractFilePath(s); | ||
| 1184 | fname := s; | ||
| 1185 | except | ||
| 1186 | Result := false; | ||
| 1187 | end; | ||
| 1188 | end; | ||
| 1189 | |||
| 1190 | function TIPKControl.LoadFromFile(s: String): Boolean; | ||
| 1191 | begin | ||
| 1192 | Result := true; | ||
| 1193 | if FileExists(s) then | ||
| 1194 | begin | ||
| 1195 | Text.LoadFromFile(s); | ||
| 1196 | if (Text[0] <> 'IPK-Standard-Version: 1.1') | ||
| 1197 | and(Text[0] <> 'IPK-Standard-Version: 1.0') then | ||
| 1198 | begin | ||
| 1199 | Result := false; | ||
| 1200 | exit; | ||
| 1201 | end; | ||
| 1202 | FBasePath := ExtractFilePath(s); | ||
| 1203 | fname := s; | ||
| 1204 | end | ||
| 1205 | else | ||
| 1206 | Result := false; | ||
| 1207 | |||
| 1208 | UseMoTranslation := true; | ||
| 1209 | end; | ||
| 1210 | |||
| 1211 | procedure TIPKControl.GetInternalFilesSection(lst: TStrings); | ||
| 1212 | var | ||
| 1213 | j: Integer; | ||
| 1214 | begin | ||
| 1215 | //Search for container-IPK files section | ||
| 1216 | j := SearchKeyIndex('Files', false); | ||
| 1217 | if j > -1 then | ||
| 1218 | begin | ||
| 1219 | ReadField('Files', lst); | ||
| 1220 | end; | ||
| 1221 | end; | ||
| 1222 | |||
| 1223 | end. |
src/ipkpackage.pas
(0 / 338)
|   | |||
| 1 | { Copyright (C) 2010 Matthias Klumpp | ||
| 2 | |||
| 3 | Authors: | ||
| 4 | Matthias Klumpp | ||
| 5 | |||
| 6 | This program is free software: you can redistribute it and/or modify it under | ||
| 7 | the terms of the GNU General Public License as published by the Free Software | ||
| 8 | Foundation, version 3. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License v3 | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.} | ||
| 16 | //** Contains class to package signed and unsigned IPK package source files | ||
| 17 | unit ipkpackage; | ||
| 18 | |||
| 19 | {$mode objfpc}{$H+} | ||
| 20 | |||
| 21 | interface | ||
| 22 | |||
| 23 | uses | ||
| 24 | Classes, FileUtil, gpgsign, liUtils, liTypes, SysUtils, TarArchive; | ||
| 25 | |||
| 26 | type | ||
| 27 | //** Creates IPK packages from preprocessed source files | ||
| 28 | |||
| 29 | { TLiPackager } | ||
| 30 | |||
| 31 | TLiPackager = class | ||
| 32 | private | ||
| 33 | OutFileName: String; | ||
| 34 | pkrandom: String; | ||
| 35 | basename: String; | ||
| 36 | mntar: TTarArchive; | ||
| 37 | finalized: Boolean; | ||
| 38 | bdir: String; | ||
| 39 | maxbytes: Int64; | ||
| 40 | |||
| 41 | function RandomID: String; | ||
| 42 | public | ||
| 43 | constructor Create(aIPKFile: String); | ||
| 44 | destructor Destroy; override; | ||
| 45 | |||
| 46 | //** Add a new file to the IPK structure @return False if already finalized or other error | ||
| 47 | function AddFile(fname: String): Boolean; | ||
| 48 | //** Finalize the base file for signing | ||
| 49 | procedure Finalize; | ||
| 50 | //** Sign the package | ||
| 51 | function SignPackage: Boolean; | ||
| 52 | //** Compress package and copy it to output @returns Success of operation | ||
| 53 | function ProduceIPKPackage: Boolean; | ||
| 54 | //** Base directory (root of package) | ||
| 55 | property BaseDir: String read bdir write bdir; | ||
| 56 | //** Set IPK file name | ||
| 57 | property IPKFile: String read OutFileName write OutFileName; | ||
| 58 | end; | ||
| 59 | |||
| 60 | //** Unpacks IPK package structure | ||
| 61 | |||
| 62 | { TLiUnpacker } | ||
| 63 | |||
| 64 | TLiUnpacker = class | ||
| 65 | private | ||
| 66 | ipkfile: String; | ||
| 67 | workdir: String; | ||
| 68 | signChecked: Boolean; | ||
| 69 | public | ||
| 70 | constructor Create(aIPKFile: String); | ||
| 71 | destructor Destroy; override; | ||
| 72 | |||
| 73 | //** Prepare IPK tar file for extracting | ||
| 74 | procedure Prepare; | ||
| 75 | //** Verify signature (if there is any) | ||
| 76 | function CheckSignature: TPkgSigState; | ||
| 77 | //** Unpack file @returns Success of operation | ||
| 78 | function UnpackFile(fname: String): Boolean; | ||
| 79 | //** Unpacker's working dir | ||
| 80 | property WDir: String read workdir; | ||
| 81 | end; | ||
| 82 | |||
| 83 | //** Create small LZMA compressed files for update sources | ||
| 84 | TLiUpdateBit = class | ||
| 85 | private | ||
| 86 | xz: TTarArchive; | ||
| 87 | public | ||
| 88 | constructor Create; | ||
| 89 | destructor Destroy; override; | ||
| 90 | |||
| 91 | //** Compress files to XZ | ||
| 92 | procedure Compress(infile: String; outfile: String); | ||
| 93 | //** Decompress a file | ||
| 94 | procedure Decompress(infile: String; outfile: String); | ||
| 95 | end; | ||
| 96 | |||
| 97 | implementation | ||
| 98 | |||
| 99 | { TLiPackager } | ||
| 100 | |||
| 101 | constructor TLiPackager.Create(aIPKFile: String); | ||
| 102 | begin | ||
| 103 | inherited Create; | ||
| 104 | randomize; | ||
| 105 | pkrandom := '-' + RandomID + RandomID + RandomID; | ||
| 106 | finalized := false; | ||
| 107 | OutFileName := aIPKFile; | ||
| 108 | basename := tmpdir + ExtractFileName(OutFileName) + pkrandom + '.tar'; | ||
| 109 | mntar := TTarArchive.Create; | ||
| 110 | mntar.Compression:=cmXZ; //IPK packages are XZ compressed | ||
| 111 | mntar.TarArchive := basename; | ||
| 112 | end; | ||
| 113 | |||
| 114 | destructor TLiPackager.Destroy; | ||
| 115 | begin | ||
| 116 | if not finalized then | ||
| 117 | mntar.Free; | ||
| 118 | inherited; | ||
| 119 | end; | ||
| 120 | |||
| 121 | function TLiPackager.RandomID: String; | ||
| 122 | begin | ||
| 123 | Result := IntToStr(random(99)); | ||
| 124 | end; | ||
| 125 | |||
| 126 | function TLiPackager.AddFile(fname: String): Boolean; | ||
| 127 | begin | ||
| 128 | if finalized then | ||
| 129 | Result := false | ||
| 130 | else | ||
| 131 | begin | ||
| 132 | mntar.BaseDir := bdir; | ||
| 133 | if mntar.AddFile(fname) = 0 then | ||
| 134 | Result := true | ||
| 135 | else | ||
| 136 | Result := false; | ||
| 137 | end; | ||
| 138 | end; | ||
| 139 | |||
| 140 | procedure TLiPackager.Finalize; | ||
| 141 | begin | ||
| 142 | p_info('Finalizing package.'); | ||
| 143 | if mntar.Finalize > 0 then | ||
| 144 | raise Exception.Create('Error while building package.'); | ||
| 145 | mntar.Free; | ||
| 146 | finalized := true; | ||
| 147 | end; | ||
| 148 | |||
| 149 | function TLiPackager.SignPackage: Boolean; | ||
| 150 | var | ||
| 151 | sign: TGPGSignWrapper; | ||
| 152 | oldbase: String; | ||
| 153 | rs: Integer; | ||
| 154 | begin | ||
| 155 | Result := false; | ||
| 156 | if (not Finalized) then | ||
| 157 | raise Exception.Create('IPK file was not finalized before signing.'); | ||
| 158 | |||
| 159 | oldbase := basename; | ||
| 160 | sign := TGPGSignWrapper.Create; | ||
| 161 | sign.FileName := oldbase; | ||
| 162 | Result := true; | ||
| 163 | if FileExistsUTF8(ExtractFilePath(oldbase) + '/signature.asc') then | ||
| 164 | DeleteFile(ExtractFilePath(oldbase) + '/signature.asc'); | ||
| 165 | |||
| 166 | if not sign.Signfile(ExtractFilePath(oldbase) + '/signature.asc') then | ||
| 167 | begin | ||
| 168 | Result := false; | ||
| 169 | sign.Free; | ||
| 170 | exit; | ||
| 171 | end; | ||
| 172 | sign.Free; | ||
| 173 | |||
| 174 | pkrandom := '-' + RandomID + RandomID + RandomID; | ||
| 175 | basename := tmpdir + ExtractFileName(OutFileName) + pkrandom + '.tar'; | ||
| 176 | mntar := TTarArchive.Create; | ||
| 177 | mntar.Compression:=cmNone; //No compression here | ||
| 178 | mntar.TarArchive := basename; | ||
| 179 | |||
| 180 | mntar.BaseDir := ExtractFilePath(oldbase); | ||
| 181 | |||
| 182 | RenameFile(oldbase, ExtractFilePath(oldbase) + '/content.tar'); | ||
| 183 | oldbase := ExtractFilePath(oldbase) + '/content.tar'; | ||
| 184 | |||
| 185 | rs := mntar.AddFile(oldbase); | ||
| 186 | if rs = 0 then | ||
| 187 | begin | ||
| 188 | rs := mntar.AddFile(ExtractFilePath(oldbase) + 'signature.asc'); | ||
| 189 | if rs <> 0 then | ||
| 190 | raise Exception.Create('Error while combining signed package.'); | ||
| 191 | end | ||
| 192 | else | ||
| 193 | raise Exception.Create('Error while combining signed package.'); | ||
| 194 | mntar.Finalize; | ||
| 195 | mntar.Free; | ||
| 196 | |||
| 197 | DeleteFile(ExtractFilePath(oldbase) + 'signature.asc'); | ||
| 198 | DeleteFile(oldbase); | ||
| 199 | end; | ||
| 200 | |||
| 201 | function TLiPackager.ProduceIPKPackage: Boolean; | ||
| 202 | begin | ||
| 203 | Result := true; | ||
| 204 | if FileExists(OutFileName) then | ||
| 205 | Exception.Create('Output file already exists!'); | ||
| 206 | if (not Finalized) then | ||
| 207 | raise Exception.Create('IPK file was not finalized.'); | ||
| 208 | |||
| 209 | if not finalized then mntar.Finalize; | ||
| 210 | |||
| 211 | FileCopy(basename,outfilename); | ||
| 212 | DeleteFile(basename); | ||
| 213 | end; | ||
| 214 | |||
| 215 | { TLiUnpacker } | ||
| 216 | |||
| 217 | constructor TLiUnpacker.Create(aIPKFile: String); | ||
| 218 | begin | ||
| 219 | inherited Create; | ||
| 220 | ipkfile := aIPKFile; | ||
| 221 | workdir := tmpdir + ExtractFileName(ipkfile) + '/'; | ||
| 222 | SysUtils.ForceDirectories(workdir); | ||
| 223 | signChecked := false; | ||
| 224 | end; | ||
| 225 | |||
| 226 | destructor TLiUnpacker.Destroy; | ||
| 227 | begin | ||
| 228 | inherited; | ||
| 229 | end; | ||
| 230 | |||
| 231 | procedure TLiUnpacker.Prepare; | ||
| 232 | begin | ||
| 233 | if not FileExists(ipkfile) then | ||
| 234 | Exception.Create('IPK file does not exists!'); | ||
| 235 | |||
| 236 | FileCopy(ipkfile, workdir+'ipktar.tar'); | ||
| 237 | //Some more praparation later... | ||
| 238 | end; | ||
| 239 | |||
| 240 | function TLiUnpacker.CheckSignature: TPkgSigState; | ||
| 241 | var | ||
| 242 | mnarc: TTarArchive; | ||
| 243 | hasSignature: Boolean; | ||
| 244 | sign: TGPGSignWrapper; | ||
| 245 | res: Integer; | ||
| 246 | begin | ||
| 247 | hasSignature := false; | ||
| 248 | mnarc := TTarArchive.Create; | ||
| 249 | mnarc.TarArchive := workdir + 'ipktar.tar'; | ||
| 250 | mnarc.Compression:=cmNone; //If we have a signature, covering tar is not compressed | ||
| 251 | mnarc.BaseDir := workdir; | ||
| 252 | |||
| 253 | Result := psNone; | ||
| 254 | //Check if package has signature | ||
| 255 | hasSignature := mnarc.FileInArchive('signature.asc'); | ||
| 256 | |||
| 257 | if hasSignature then | ||
| 258 | begin | ||
| 259 | res := mnarc.ExtractFile('signature.asc'); | ||
| 260 | res += mnarc.ExtractFile('content.tar'); | ||
| 261 | |||
| 262 | if res <> 0 then | ||
| 263 | begin | ||
| 264 | //!!! This should be done better! | ||
| 265 | raise Exception.Create('Could not verify signature!'); | ||
| 266 | end; | ||
| 267 | |||
| 268 | DeleteFile(workdir + 'ipktar.tar'); | ||
| 269 | RenameFile(workdir + 'content.tar', workdir + 'ipktar.tar'); | ||
| 270 | Result := psUntrusted; | ||
| 271 | //Now check signature | ||
| 272 | sign := TGPGSignWrapper.Create; | ||
| 273 | sign.FileName := workdir + 'ipktar.tar'; | ||
| 274 | if sign.Verify(workdir + 'signature.asc') then | ||
| 275 | Result := psTrusted; | ||
| 276 | sign.Free; | ||
| 277 | end; | ||
| 278 | mnarc.Free; | ||
| 279 | signChecked := true; | ||
| 280 | end; | ||
| 281 | |||
| 282 | function TLiUnpacker.UnpackFile(fname: String): Boolean; | ||
| 283 | var | ||
| 284 | arc: TTarArchive; | ||
| 285 | begin | ||
| 286 | if not signChecked then | ||
| 287 | CheckSignature; | ||
| 288 | Result := false; | ||
| 289 | if length(fname) < 2 then | ||
| 290 | exit; | ||
| 291 | |||
| 292 | fname := CleanFilePath(fname); | ||
| 293 | |||
| 294 | arc := TTarArchive.Create; | ||
| 295 | arc.TarArchive := workdir + 'ipktar.tar'; | ||
| 296 | arc.BaseDir := workdir; | ||
| 297 | arc.Compression:=cmXZ; | ||
| 298 | //Create dir struct | ||
| 299 | //ForceDirectories(ExtractFilePath(fdest)); | ||
| 300 | //Check if package has signature | ||
| 301 | if arc.ExtractFile(fname) = 0 then | ||
| 302 | Result := true; | ||
| 303 | |||
| 304 | arc.Free; | ||
| 305 | end; | ||
| 306 | |||
| 307 | { TLiUpdateBit } | ||
| 308 | |||
| 309 | constructor TLiUpdateBit.Create; | ||
| 310 | begin | ||
| 311 | inherited; | ||
| 312 | xz := TTarArchive.Create; | ||
| 313 | xz.Compression:=cmLZMA; | ||
| 314 | end; | ||
| 315 | |||
| 316 | destructor TLiUpdateBit.Destroy; | ||
| 317 | begin | ||
| 318 | xz.Free; | ||
| 319 | inherited; | ||
| 320 | end; | ||
| 321 | |||
| 322 | procedure TLiUpdateBit.Compress(infile: String; outfile: String); | ||
| 323 | begin | ||
| 324 | xz.BaseDir:=ExtractFilePath(infile); | ||
| 325 | xz.TarArchive:=outfile; | ||
| 326 | xz.AddFile(infile); | ||
| 327 | xz.Finalize; | ||
| 328 | end; | ||
| 329 | |||
| 330 | procedure TLiUpdateBit.Decompress(infile: String; outfile: String); | ||
| 331 | begin | ||
| 332 | //NEEDS WORK! | ||
| 333 | xz.TarArchive:=infile; | ||
| 334 | xz.BaseDir:=ExtractFilePath(outfile); | ||
| 335 | xz.ExtractFile('*'); | ||
| 336 | end; | ||
| 337 | |||
| 338 | end. |
src/ipkpackage11.pas
(338 / 0)
|   | |||
| 1 | { Copyright (C) 2010 Matthias Klumpp | ||
| 2 | |||
| 3 | Authors: | ||
| 4 | Matthias Klumpp | ||
| 5 | |||
| 6 | This program is free software: you can redistribute it and/or modify it under | ||
| 7 | the terms of the GNU General Public License as published by the Free Software | ||
| 8 | Foundation, version 3. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License v3 | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.} | ||
| 16 | //** Contains class to package signed and unsigned IPK package source files (IPK1.1 layout) | ||
| 17 | unit ipkpackage11; | ||
| 18 | |||
| 19 | {$mode objfpc}{$H+} | ||
| 20 | |||
| 21 | interface | ||
| 22 | |||
| 23 | uses | ||
| 24 | Classes, FileUtil, GPGSign, LiUtils, LiTypes, SysUtils, TarArchive; | ||
| 25 | |||
| 26 | type | ||
| 27 | //** Creates IPK packages from preprocessed source files | ||
| 28 | |||
| 29 | { TLiPackager } | ||
| 30 | |||
| 31 | TLiPackager = class | ||
| 32 | private | ||
| 33 | OutFileName: String; | ||
| 34 | pkrandom: String; | ||
| 35 | basename: String; | ||
| 36 | mntar: TTarArchive; | ||
| 37 | finalized: Boolean; | ||
| 38 | bdir: String; | ||
| 39 | maxbytes: Int64; | ||
| 40 | |||
| 41 | function RandomID: String; | ||
| 42 | public | ||
| 43 | constructor Create(aIPKFile: String); | ||
| 44 | destructor Destroy; override; | ||
| 45 | |||
| 46 | //** Add a new file to the IPK structure @return False if already finalized or other error | ||
| 47 | function AddFile(fname: String): Boolean; | ||
| 48 | //** Finalize the base file for signing | ||
| 49 | procedure Finalize; | ||
| 50 | //** Sign the package | ||
| 51 | function SignPackage: Boolean; | ||
| 52 | //** Compress package and copy it to output @returns Success of operation | ||
| 53 | function ProduceIPKPackage: Boolean; | ||
| 54 | //** Base directory (root of package) | ||
| 55 | property BaseDir: String read bdir write bdir; | ||
| 56 | //** Set IPK file name | ||
| 57 | property IPKFile: String read OutFileName write OutFileName; | ||
| 58 | end; | ||
| 59 | |||
| 60 | //** Unpacks IPK package structure | ||
| 61 | |||
| 62 | { TLiUnpacker } | ||
| 63 | |||
| 64 | TLiUnpacker = class | ||
| 65 | private | ||
| 66 | ipkfile: String; | ||
| 67 | workdir: String; | ||
| 68 | signChecked: Boolean; | ||
| 69 | public | ||
| 70 | constructor Create(aIPKFile: String); | ||
| 71 | destructor Destroy; override; | ||
| 72 | |||
| 73 | //** Prepare IPK tar file for extracting | ||
| 74 | procedure Prepare; | ||
| 75 | //** Verify signature (if there is any) | ||
| 76 | function CheckSignature: TPkgSigState; | ||
| 77 | //** Unpack file @returns Success of operation | ||
| 78 | function UnpackFile(fname: String): Boolean; | ||
| 79 | //** Unpacker's working dir | ||
| 80 | property WDir: String read workdir; | ||
| 81 | end; | ||
| 82 | |||
| 83 | //** Create small LZMA compressed files for update sources | ||
| 84 | TLiUpdateBit = class | ||
| 85 | private | ||
| 86 | xz: TTarArchive; | ||
| 87 | public | ||
| 88 | constructor Create; | ||
| 89 | destructor Destroy; override; | ||
| 90 | |||
| 91 | //** Compress files to XZ | ||
| 92 | procedure Compress(infile: String; outfile: String); | ||
| 93 | //** Decompress a file | ||
| 94 | procedure Decompress(infile: String; outfile: String); | ||
| 95 | end; | ||
| 96 | |||
| 97 | implementation | ||
| 98 | |||
| 99 | { TLiPackager } | ||
| 100 | |||
| 101 | constructor TLiPackager.Create(aIPKFile: String); | ||
| 102 | begin | ||
| 103 | inherited Create; | ||
| 104 | randomize; | ||
| 105 | pkrandom := '-' + RandomID + RandomID + RandomID; | ||
| 106 | finalized := false; | ||
| 107 | OutFileName := aIPKFile; | ||
| 108 | basename := tmpdir + ExtractFileName(OutFileName) + pkrandom + '.tar'; | ||
| 109 | mntar := TTarArchive.Create; | ||
| 110 | mntar.Compression:=cmXZ; //IPK packages are XZ compressed | ||
| 111 | mntar.TarArchive := basename; | ||
| 112 | end; | ||
| 113 | |||
| 114 | destructor TLiPackager.Destroy; | ||
| 115 | begin | ||
| 116 | if not finalized then | ||
| 117 | mntar.Free; | ||
| 118 | inherited; | ||
| 119 | end; | ||
| 120 | |||
| 121 | function TLiPackager.RandomID: String; | ||
| 122 | begin | ||
| 123 | Result := IntToStr(random(99)); | ||
| 124 | end; | ||
| 125 | |||
| 126 | function TLiPackager.AddFile(fname: String): Boolean; | ||
| 127 | begin | ||
| 128 | if finalized then | ||
| 129 | Result := false | ||
| 130 | else | ||
| 131 | begin | ||
| 132 | mntar.BaseDir := bdir; | ||
| 133 | if mntar.AddFile(fname) = 0 then | ||
| 134 | Result := true | ||
| 135 | else | ||
| 136 | Result := false; | ||
| 137 | end; | ||
| 138 | end; | ||
| 139 | |||
| 140 | procedure TLiPackager.Finalize; | ||
| 141 | begin | ||
| 142 | p_info('Finalizing package.'); | ||
| 143 | if mntar.Finalize > 0 then | ||
| 144 | raise Exception.Create('Error while building package.'); | ||
| 145 | mntar.Free; | ||
| 146 | finalized := true; | ||
| 147 | end; | ||
| 148 | |||
| 149 | function TLiPackager.SignPackage: Boolean; | ||
| 150 | var | ||
| 151 | sign: TGPGSignWrapper; | ||
| 152 | oldbase: String; | ||
| 153 | rs: Integer; | ||
| 154 | begin | ||
| 155 | Result := false; | ||
| 156 | if (not Finalized) then | ||
| 157 | raise Exception.Create('IPK file was not finalized before signing.'); | ||
| 158 | |||
| 159 | oldbase := basename; | ||
| 160 | sign := TGPGSignWrapper.Create; | ||
| 161 | sign.FileName := oldbase; | ||
| 162 | Result := true; | ||
| 163 | if FileExistsUTF8(ExtractFilePath(oldbase) + '/signature.asc') then | ||
| 164 | DeleteFile(ExtractFilePath(oldbase) + '/signature.asc'); | ||
| 165 | |||
| 166 | if not sign.Signfile(ExtractFilePath(oldbase) + '/signature.asc') then | ||
| 167 | begin | ||
| 168 | Result := false; | ||
| 169 | sign.Free; | ||
| 170 | exit; | ||
| 171 | end; | ||
| 172 | sign.Free; | ||
| 173 | |||
| 174 | pkrandom := '-' + RandomID + RandomID + RandomID; | ||
| 175 | basename := tmpdir + ExtractFileName(OutFileName) + pkrandom + '.tar'; | ||
| 176 | mntar := TTarArchive.Create; | ||
| 177 | mntar.Compression:=cmNone; //No compression here | ||
| 178 | mntar.TarArchive := basename; | ||
| 179 | |||
| 180 | mntar.BaseDir := ExtractFilePath(oldbase); | ||
| 181 | |||
| 182 | RenameFile(oldbase, ExtractFilePath(oldbase) + '/content.tar'); | ||
| 183 | oldbase := ExtractFilePath(oldbase) + '/content.tar'; | ||
| 184 | |||
| 185 | rs := mntar.AddFile(oldbase); | ||
| 186 | if rs = 0 then | ||
| 187 | begin | ||
| 188 | rs := mntar.AddFile(ExtractFilePath(oldbase) + 'signature.asc'); | ||
| 189 | if rs <> 0 then | ||
| 190 | raise Exception.Create('Error while combining signed package.'); | ||
| 191 | end | ||
| 192 | else | ||
| 193 | raise Exception.Create('Error while combining signed package.'); | ||
| 194 | mntar.Finalize; | ||
| 195 | mntar.Free; | ||
| 196 | |||
| 197 | DeleteFile(ExtractFilePath(oldbase) + 'signature.asc'); | ||
| 198 | DeleteFile(oldbase); | ||
| 199 | end; | ||
| 200 | |||
| 201 | function TLiPackager.ProduceIPKPackage: Boolean; | ||
| 202 | begin | ||
| 203 | Result := true; | ||
| 204 | if FileExists(OutFileName) then | ||
| 205 | Exception.Create('Output file already exists!'); | ||
| 206 | if (not Finalized) then | ||
| 207 | raise Exception.Create('IPK file was not finalized.'); | ||
| 208 | |||
| 209 | if not finalized then mntar.Finalize; | ||
| 210 | |||
| 211 | FileCopy(basename,outfilename); | ||
| 212 | DeleteFile(basename); | ||
| 213 | end; | ||
| 214 | |||
| 215 | { TLiUnpacker } | ||
| 216 | |||
| 217 | constructor TLiUnpacker.Create(aIPKFile: String); | ||
| 218 | begin | ||
| 219 | inherited Create; | ||
| 220 | ipkfile := aIPKFile; | ||
| 221 | workdir := tmpdir + ExtractFileName(ipkfile) + '/'; | ||
| 222 | SysUtils.ForceDirectories(workdir); | ||
| 223 | signChecked := false; | ||
| 224 | end; | ||
| 225 | |||
| 226 | destructor TLiUnpacker.Destroy; | ||
| 227 | begin | ||
| 228 | inherited; | ||
| 229 | end; | ||
| 230 | |||
| 231 | procedure TLiUnpacker.Prepare; | ||
| 232 | begin | ||
| 233 | if not FileExists(ipkfile) then | ||
| 234 | Exception.Create('IPK file does not exists!'); | ||
| 235 | |||
| 236 | FileCopy(ipkfile, workdir+'ipktar.tar'); | ||
| 237 | //Some more praparation later... | ||
| 238 | end; | ||
| 239 | |||
| 240 | function TLiUnpacker.CheckSignature: TPkgSigState; | ||
| 241 | var | ||
| 242 | mnarc: TTarArchive; | ||
| 243 | hasSignature: Boolean; | ||
| 244 | sign: TGPGSignWrapper; | ||
| 245 | res: Integer; | ||
| 246 | begin | ||
| 247 | hasSignature := false; | ||
| 248 | mnarc := TTarArchive.Create; | ||
| 249 | mnarc.TarArchive := workdir + 'ipktar.tar'; | ||
| 250 | mnarc.Compression:=cmNone; //If we have a signature, covering tar is not compressed | ||
| 251 | mnarc.BaseDir := workdir; | ||
| 252 | |||
| 253 | Result := psNone; | ||
| 254 | //Check if package has signature | ||
| 255 | hasSignature := mnarc.FileInArchive('signature.asc'); | ||
| 256 | |||
| 257 | if hasSignature then | ||
| 258 | begin | ||
| 259 | res := mnarc.ExtractFile('signature.asc'); | ||
| 260 | res += mnarc.ExtractFile('content.tar'); | ||
| 261 | |||
| 262 | if res <> 0 then | ||
| 263 | begin | ||
| 264 | //!!! This should be done better! | ||
| 265 | raise Exception.Create('Could not verify signature!'); | ||
| 266 | end; | ||
| 267 | |||
| 268 | DeleteFile(workdir + 'ipktar.tar'); | ||
| 269 | RenameFile(workdir + 'content.tar', workdir + 'ipktar.tar'); | ||
| 270 | Result := psUntrusted; | ||
| 271 | //Now check signature | ||
| 272 | sign := TGPGSignWrapper.Create; | ||
| 273 | sign.FileName := workdir + 'ipktar.tar'; | ||
| 274 | if sign.Verify(workdir + 'signature.asc') then | ||
| 275 | Result := psTrusted; | ||
| 276 | sign.Free; | ||
| 277 | end; | ||
| 278 | mnarc.Free; | ||
| 279 | signChecked := true; | ||
| 280 | end; | ||
| 281 | |||
| 282 | function TLiUnpacker.UnpackFile(fname: String): Boolean; | ||
| 283 | var | ||
| 284 | arc: TTarArchive; | ||
| 285 | begin | ||
| 286 | if not signChecked then | ||
| 287 | CheckSignature; | ||
| 288 | Result := false; | ||
| 289 | if length(fname) < 2 then | ||
| 290 | exit; | ||
| 291 | |||
| 292 | fname := CleanFilePath(fname); | ||
| 293 | |||
| 294 | arc := TTarArchive.Create; | ||
| 295 | arc.TarArchive := workdir + 'ipktar.tar'; | ||
| 296 | arc.BaseDir := workdir; | ||
| 297 | arc.Compression:=cmXZ; | ||
| 298 | //Create dir struct | ||
| 299 | //ForceDirectories(ExtractFilePath(fdest)); | ||
| 300 | //Check if package has signature | ||
| 301 | if arc.ExtractFile(fname) = 0 then | ||
| 302 | Result := true; | ||
| 303 | |||
| 304 | arc.Free; | ||
| 305 | end; | ||
| 306 | |||
| 307 | { TLiUpdateBit } | ||
| 308 | |||
| 309 | constructor TLiUpdateBit.Create; | ||
| 310 | begin | ||
| 311 | inherited; | ||
| 312 | xz := TTarArchive.Create; | ||
| 313 | xz.Compression:=cmLZMA; | ||
| 314 | end; | ||
| 315 | |||
| 316 | destructor TLiUpdateBit.Destroy; | ||
| 317 | begin | ||
| 318 | xz.Free; | ||
| 319 | inherited; | ||
| 320 | end; | ||
| 321 | |||
| 322 | procedure TLiUpdateBit.Compress(infile: String; outfile: String); | ||
| 323 | begin | ||
| 324 | xz.BaseDir:=ExtractFilePath(infile); | ||
| 325 | xz.TarArchive:=outfile; | ||
| 326 | xz.AddFile(infile); | ||
| 327 | xz.Finalize; | ||
| 328 | end; | ||
| 329 | |||
| 330 | procedure TLiUpdateBit.Decompress(infile: String; outfile: String); | ||
| 331 | begin | ||
| 332 | //NEEDS WORK! | ||
| 333 | xz.TarArchive:=infile; | ||
| 334 | xz.BaseDir:=ExtractFilePath(outfile); | ||
| 335 | xz.ExtractFile('*'); | ||
| 336 | end; | ||
| 337 | |||
| 338 | end. |
src/licreator/prjwizard.pas
(2 / 2)
|   | |||
| 22 | 22 | interface | |
| 23 | 23 | ||
| 24 | 24 | uses | |
| 25 | MD5, Forms, Grids, Menus, editor, ipkdef, Buttons, Classes, Dialogs, | ||
| 25 | MD5, Forms, Grids, Menus, editor, IPKCDef10, Buttons, Classes, Dialogs, | ||
| 26 | 26 | EditBtn, LCLType, LiTypes, liUtils, SynEdit, CheckLst, ComCtrls, | |
| 27 | 27 | Controls, ExtCtrls, FileCtrl, FileUtil, Graphics, StdCtrls, | |
| 28 | SysUtils, IconLoader, LResources, popupnotifier; | ||
| 28 | SysUtils, IconLoader, LResources, PopupNotifier; | ||
| 29 | 29 | ||
| 30 | 30 | type | |
| 31 | 31 |
src/litranslator.pas
(169 / 129)
|   | |||
| 24 | 24 | interface | |
| 25 | 25 | ||
| 26 | 26 | uses | |
| 27 | Classes, SysUtils, LResources, GetText, Controls, typinfo, FileUtil, | ||
| 28 | LiUtils; | ||
| 27 | Classes, GetText, LiUtils, TypInfo, Controls, FileUtil, | ||
| 28 | SysUtils, LResources; | ||
| 29 | 29 | ||
| 30 | 30 | type | |
| 31 | TDefaultTranslator=class(TAbstractTranslator) | ||
| 32 | private | ||
| 33 | FMOFile:TMOFile; | ||
| 34 | public | ||
| 35 | constructor Create(MOFileName:string); | ||
| 36 | destructor Destroy;override; | ||
| 37 | procedure TranslateStringProperty(Sender:TObject; const Instance: TPersistent; PropInfo: PPropInfo; var Content:string);override; | ||
| 38 | end; | ||
| 31 | TDefaultTranslator = class(TAbstractTranslator) | ||
| 32 | private | ||
| 33 | FMOFile: TMOFile; | ||
| 34 | public | ||
| 35 | constructor Create(MOFileName: String); | ||
| 36 | destructor Destroy; override; | ||
| 37 | procedure TranslateStringProperty(Sender: TObject; const Instance: TPersistent; | ||
| 38 | PropInfo: PPropInfo; var Content: String); override; | ||
| 39 | end; | ||
| 39 | 40 | ||
| 40 | 41 | implementation | |
| 42 | |||
| 41 | 43 | uses Menus; | |
| 42 | 44 | ||
| 43 | function FindLocaleFileName:string; | ||
| 44 | var LANG,lng:string; | ||
| 45 | function FindLocaleFileName: String; | ||
| 46 | var | ||
| 47 | LANG, lng: String; | ||
| 45 | 48 | i: Integer; | |
| 46 | 49 | liname: String; | |
| 47 | 50 | begin | |
| 48 | LANG:=GetEnvironmentVariableUTF8('LANG'); | ||
| 49 | if LANG='' then begin | ||
| 50 | for i:=1 to Paramcount-1 do | ||
| 51 | if (ParamStrUTF8(i)='--LANG') or | ||
| 52 | (ParamStrUTF8(i)='-l') or | ||
| 53 | (ParamStrUTF8(i)='--lang') then LANG:=ParamStrUTF8(i+1); | ||
| 54 | end; | ||
| 51 | LANG := GetEnvironmentVariableUTF8('LANG'); | ||
| 52 | if LANG = '' then | ||
| 53 | begin | ||
| 54 | for i := 1 to Paramcount - 1 do | ||
| 55 | if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or | ||
| 56 | (ParamStrUTF8(i) = '--lang') then | ||
| 57 | LANG := ParamStrUTF8(i + 1); | ||
| 58 | end; | ||
| 55 | 59 | ||
| 56 | liname:='listaller'; | ||
| 60 | liname := 'listaller'; | ||
| 57 | 61 | ||
| 58 | if LANG<>'' then begin | ||
| 59 | //ParamStrUTF8(0) is said not to work properly in linux, but I've tested it | ||
| 60 | Result:=ExtractFilePath(ParamStrUTF8(0))+LANG+ | ||
| 61 | DirectorySeparator+liname+'.mo'; | ||
| 62 | if FileExistsUTF8(Result) then exit; | ||
| 62 | if LANG <> '' then | ||
| 63 | begin | ||
| 64 | //ParamStrUTF8(0) is said not to work properly in linux, but I've tested it | ||
| 65 | Result := ExtractFilePath(ParamStrUTF8(0)) + LANG + DirectorySeparator + liname + '.mo'; | ||
| 66 | if FileExistsUTF8(Result) then | ||
| 67 | exit; | ||
| 63 | 68 | ||
| 64 | Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+LANG+ | ||
| 65 | DirectorySeparator+liname+'.mo'; | ||
| 66 | if FileExistsUTF8(Result) then exit; | ||
| 69 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + LANG + | ||
| 70 | DirectorySeparator + liname + '.mo'; | ||
| 71 | if FileExistsUTF8(Result) then | ||
| 72 | exit; | ||
| 67 | 73 | ||
| 68 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator | ||
| 69 | +LANG+DirectorySeparator+liname+'.mo'; | ||
| 70 | if FileExistsUTF8(Result) then exit; | ||
| 74 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator | ||
| 75 | + LANG + DirectorySeparator + liname + '.mo'; | ||
| 76 | if FileExistsUTF8(Result) then | ||
| 77 | exit; | ||
| 71 | 78 | ||
| 72 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator | ||
| 73 | +LANG+DirectorySeparator+'LC_MESSAGES'+DirectorySeparator+ | ||
| 74 | liname+'.mo'; | ||
| 75 | if FileExistsUTF8(Result) then exit; | ||
| 79 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator | ||
| 80 | + LANG + DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + liname + '.mo'; | ||
| 81 | if FileExistsUTF8(Result) then | ||
| 82 | exit; | ||
| 76 | 83 | ||
| 77 | //In unix-like systems we can try to search for global locale | ||
| 78 | Result:='/usr/share/locale/'+LANG+'/LC_MESSAGES/' | ||
| 79 | +liname+'.mo'; | ||
| 80 | if FileExistsUTF8(Result) then exit; | ||
| 84 | //In unix-like systems we can try to search for global locale | ||
| 85 | Result := '/usr/share/locale/' + LANG + '/LC_MESSAGES/' + liname + '.mo'; | ||
| 86 | if FileExistsUTF8(Result) then | ||
| 87 | exit; | ||
| 81 | 88 | ||
| 82 | //Let us search for reducted files | ||
| 83 | lng:=copy(LANG,1,2); | ||
| 89 | //Let us search for reducted files | ||
| 90 | lng := copy(LANG, 1, 2); | ||
| 84 | 91 | ||
| 85 | Result:='/usr/share/listaller/locale/'+lng+'.mo'; | ||
| 86 | if FileExistsUTF8(Result) then exit; | ||
| 92 | Result := '/usr/share/listaller/locale/' + lng + '.mo'; | ||
| 93 | if FileExistsUTF8(Result) then | ||
| 94 | exit; | ||
| 87 | 95 | ||
| 88 | Result:='/usr/share/listaller/locale/'+liname+'-'+lng+'.mo'; | ||
| 89 | if FileExistsUTF8(Result) then exit; | ||
| 96 | Result := '/usr/share/listaller/locale/' + liname + '-' + lng + '.mo'; | ||
| 97 | if FileExistsUTF8(Result) then | ||
| 98 | exit; | ||
| 90 | 99 | ||
| 91 | Result:='/usr/share/listaller/locale/'+LANG+'.mo'; | ||
| 92 | if FileExistsUTF8(Result) then exit; | ||
| 100 | Result := '/usr/share/listaller/locale/' + LANG + '.mo'; | ||
| 101 | if FileExistsUTF8(Result) then | ||
| 102 | exit; | ||
| 93 | 103 | ||
| 94 | Result:='/usr/share/listaller/locale/'+liname+'-'+LANG+'.mo'; | ||
| 95 | if FileExistsUTF8(Result) then exit; | ||
| 104 | Result := '/usr/share/listaller/locale/' + liname + '-' + LANG + '.mo'; | ||
| 105 | if FileExistsUTF8(Result) then | ||
| 106 | exit; | ||
| 96 | 107 | ||
| 97 | //At first, check all was checked | ||
| 98 | Result:=ExtractFilePath(ParamStrUTF8(0))+lng+ | ||
| 99 | DirectorySeparator+liname+'.mo'; | ||
| 100 | if FileExistsUTF8(Result) then exit; | ||
| 108 | //At first, check all was checked | ||
| 109 | Result := ExtractFilePath(ParamStrUTF8(0)) + lng + DirectorySeparator + liname + '.mo'; | ||
| 110 | if FileExistsUTF8(Result) then | ||
| 111 | exit; | ||
| 101 | 112 | ||
| 102 | Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+lng+ | ||
| 103 | DirectorySeparator+liname+'.mo'; | ||
| 104 | if FileExistsUTF8(Result) then exit; | ||
| 113 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + lng + | ||
| 114 | DirectorySeparator + liname + '.mo'; | ||
| 115 | if FileExistsUTF8(Result) then | ||
| 116 | exit; | ||
| 105 | 117 | ||
| 106 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator | ||
| 107 | +lng+DirectorySeparator+liname+'.mo'; | ||
| 108 | if FileExistsUTF8(Result) then exit; | ||
| 118 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator | ||
| 119 | + lng + DirectorySeparator + liname + '.mo'; | ||
| 120 | if FileExistsUTF8(Result) then | ||
| 121 | exit; | ||
| 109 | 122 | ||
| 110 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator | ||
| 111 | +LANG+DirectorySeparator+'LC_MESSAGES'+DirectorySeparator+ | ||
| 112 | liname+'.mo'; | ||
| 113 | if FileExistsUTF8(Result) then exit; | ||
| 123 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator | ||
| 124 | + LANG + DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + liname + '.mo'; | ||
| 125 | if FileExistsUTF8(Result) then | ||
| 126 | exit; | ||
| 114 | 127 | ||
| 115 | //Full language in file name - this will be default for the project | ||
| 116 | //We need more carefull handling, as it MAY result in incorrect filename | ||
| 117 | try | ||
| 118 | Result:=ExtractFilePath(ParamStrUTF8(0))+liname+'.'+LANG+'.mo'; | ||
| 119 | if FileExistsUTF8(Result) then exit; | ||
| 120 | //Common location (like in Lazarus) | ||
| 121 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+liname+'.'+LANG+'.mo'; | ||
| 122 | if FileExistsUTF8(Result) then exit; | ||
| 128 | //Full language in file name - this will be default for the project | ||
| 129 | //We need more carefull handling, as it MAY result in incorrect filename | ||
| 130 | try | ||
| 131 | Result := ExtractFilePath(ParamStrUTF8(0)) + liname + '.' + LANG + '.mo'; | ||
| 132 | if FileExistsUTF8(Result) then | ||
| 133 | exit; | ||
| 134 | //Common location (like in Lazarus) | ||
| 135 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + | ||
| 136 | liname + '.' + LANG + '.mo'; | ||
| 137 | if FileExistsUTF8(Result) then | ||
| 138 | exit; | ||
| 123 | 139 | ||
| 124 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+liname+'-'+LANG+'.mo'; | ||
| 125 | if FileExistsUTF8(Result) then exit; | ||
| 140 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + | ||
| 141 | liname + '-' + LANG + '.mo'; | ||
| 142 | if FileExistsUTF8(Result) then | ||
| 143 | exit; | ||
| 126 | 144 | ||
| 127 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+LANG+'.mo'; | ||
| 128 | if FileExistsUTF8(Result) then exit; | ||
| 145 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + LANG + '.mo'; | ||
| 146 | if FileExistsUTF8(Result) then | ||
| 147 | exit; | ||
| 129 | 148 | ||
| 130 | Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+liname+'.'+LANG+'.mo'; | ||
| 131 | if FileExistsUTF8(Result) then exit; | ||
| 132 | except | ||
| 133 | end; | ||
| 134 | Result:='/usr/share/locale/'+lng+'/LC_MESSAGES/' | ||
| 135 | +liname+'.mo'; | ||
| 136 | if FileExistsUTF8(Result) then exit; | ||
| 149 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + | ||
| 150 | liname + '.' + LANG + '.mo'; | ||
| 151 | if FileExistsUTF8(Result) then | ||
| 152 | exit; | ||
| 153 | except | ||
| 154 | end; | ||
| 155 | Result := '/usr/share/locale/' + lng + '/LC_MESSAGES/' + liname + '.mo'; | ||
| 156 | if FileExistsUTF8(Result) then | ||
| 157 | exit; | ||
| 137 | 158 | ||
| 138 | Result:=ExtractFilePath(ParamStrUTF8(0))+liname+'.'+lng+'.mo'; | ||
| 139 | if FileExistsUTF8(Result) then exit; | ||
| 159 | Result := ExtractFilePath(ParamStrUTF8(0)) + liname + '.' + lng + '.mo'; | ||
| 160 | if FileExistsUTF8(Result) then | ||
| 161 | exit; | ||
| 140 | 162 | ||
| 141 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+liname+'.'+lng+'.mo'; | ||
| 142 | if FileExistsUTF8(Result) then exit; | ||
| 163 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + | ||
| 164 | liname + '.' + lng + '.mo'; | ||
| 165 | if FileExistsUTF8(Result) then | ||
| 166 | exit; | ||
| 143 | 167 | ||
| 144 | Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+liname+'-'+lng+'.mo'; | ||
| 145 | if FileExistsUTF8(Result) then exit; | ||
| 168 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + | ||
| 169 | liname + '-' + lng + '.mo'; | ||
| 170 | if FileExistsUTF8(Result) then | ||
| 171 | exit; | ||
| 146 | 172 | ||
| 147 | Result:=GetDataFile('/locale/'+liname+'-'+lng+'.mo'); | ||
| 148 | if FileExistsUTF8(Result) then exit; | ||
| 173 | Result := GetDataFile('/locale/' + liname + '-' + lng + '.mo'); | ||
| 174 | if FileExistsUTF8(Result) then | ||
| 175 | exit; | ||
| 149 | 176 | ||
| 150 | Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+liname+'.'+lng+'.mo'; | ||
| 151 | if FileExistsUTF8(Result) then exit; | ||
| 152 | end; | ||
| 153 | Result:=ChangeFileExt(ParamStrUTF8(0),'.mo'); | ||
| 154 | if FileExistsUTF8(Result) then exit; | ||
| 177 | Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + | ||
| 178 | liname + '.' + lng + '.mo'; | ||
| 179 | if FileExistsUTF8(Result) then | ||
| 180 | exit; | ||
| 181 | end; | ||
| 182 | Result := ChangeFileExt(ParamStrUTF8(0), '.mo'); | ||
| 183 | if FileExistsUTF8(Result) then | ||
| 184 | exit; | ||
| 155 | 185 | ||
| 156 | Result:=''; | ||
| 186 | Result := ''; | ||
| 157 | 187 | end; | |
| 158 | var lcfn:string; | ||
| 159 | 188 | ||
| 189 | var | ||
| 190 | lcfn: String; | ||
| 191 | |||
| 160 | 192 | { TDefaultTranslator } | |
| 161 | 193 | ||
| 162 | constructor TDefaultTranslator.Create(MOFileName: string); | ||
| 163 | var lng: String; | ||
| 194 | constructor TDefaultTranslator.Create(MOFileName: String); | ||
| 195 | var | ||
| 196 | lng: String; | ||
| 164 | 197 | begin | |
| 165 | 198 | inherited Create; | |
| 166 | FMOFile:=TMOFile.Create(UTF8ToSys(MOFileName)); | ||
| 199 | FMOFile := TMOFile.Create(UTF8ToSys(MOFileName)); | ||
| 167 | 200 | ||
| 168 | lng:=copy(GetEnvironmentVariableUTF8('LANG'),1,2); | ||
| 169 | if FileExistsUTF8('/usr/share/listaller/locale/lclstrconsts-'+lng+'.mo') then | ||
| 170 | TranslateResourceStrings('/usr/share/listaller/locale/lclstrconsts-'+lng+'.mo'); | ||
| 201 | lng := copy(GetEnvironmentVariableUTF8('LANG'), 1, 2); | ||
| 202 | if FileExistsUTF8('/usr/share/listaller/locale/lclstrconsts-' + lng + '.mo') then | ||
| 203 | TranslateResourceStrings('/usr/share/listaller/locale/lclstrconsts-' + lng + '.mo'); | ||
| 171 | 204 | end; | |
| 172 | 205 | ||
| 173 | 206 | destructor TDefaultTranslator.Destroy; | |
| 174 | 207 | begin | |
| 175 | 208 | FMOFile.Free; | |
| 176 | //If someone will use this class incorrectly, it can be destroyed | ||
| 177 | //before Reader destroying. It is a very bad thing, but in THIS situation | ||
| 178 | //in this case is impossible. May be, in future we can overcome this difficulty | ||
| 209 | //If someone will use this class incorrectly, it can be destroyed | ||
| 210 | //before Reader destroying. It is a very bad thing, but in THIS situation | ||
| 211 | //in this case is impossible. May be, in future we can overcome this difficulty | ||
| 179 | 212 | inherited Destroy; | |
| 180 | 213 | end; | |
| 181 | 214 | ||
| 182 | 215 | procedure TDefaultTranslator.TranslateStringProperty(Sender: TObject; | |
| 183 | const Instance: TPersistent; PropInfo: PPropInfo; var Content: string); | ||
| 216 | const Instance: TPersistent; PropInfo: PPropInfo; var Content: String); | ||
| 184 | 217 | var | |
| 185 | 218 | s: String; | |
| 186 | 219 | begin | |
| 187 | if not Assigned(FMOFile) then exit; | ||
| 188 | if not Assigned(PropInfo) then exit; | ||
| 189 | {DO we really need this?} | ||
| 220 | if not Assigned(FMOFile) then | ||
| 221 | exit; | ||
| 222 | if not Assigned(PropInfo) then | ||
| 223 | exit; | ||
| 224 | {DO we really need this?} | ||
| 190 | 225 | if Instance is TComponent then | |
| 191 | if csDesigning in (Instance as TComponent).ComponentState then exit; | ||
| 192 | {End DO :)} | ||
| 193 | if (AnsiUpperCase(PropInfo^.PropType^.Name)<>'TTRANSLATESTRING') then exit; | ||
| 194 | s:=FMOFile.Translate(Content); | ||
| 195 | if s<>'' then Content:=s; | ||
| 226 | if csDesigning in (Instance as TComponent).ComponentState then | ||
| 227 | exit; | ||
| 228 | {End DO :)} | ||
| 229 | if (AnsiUpperCase(PropInfo^.PropType^.Name) <> 'TTRANSLATESTRING') then | ||
| 230 | exit; | ||
| 231 | s := FMOFile.Translate(Content); | ||
| 232 | if s <> '' then | ||
| 233 | Content := s; | ||
| 196 | 234 | end; | |
| 197 | 235 | ||
| 198 | var Dot1:integer; | ||
| 199 | LCLPath:string; | ||
| 236 | var | ||
| 237 | Dot1: Integer; | ||
| 238 | LCLPath: String; | ||
| 239 | |||
| 200 | 240 | initialization | |
| 201 | //It is safe to place code here as no form is initialized before unit | ||
| 202 | //initialization made | ||
| 203 | //We are to search for all | ||
| 241 | //It is safe to place code here as no form is initialized before unit | ||
| 242 | //initialization made | ||
| 243 | //We are to search for all | ||
| 204 | 244 | try | |
| 205 | lcfn:=FindLocaleFileName; | ||
| 245 | lcfn := FindLocaleFileName; | ||
| 206 | 246 | except | |
| 207 | lcfn:=''; | ||
| 247 | lcfn := ''; | ||
| 208 | 248 | end; | |
| 209 | 249 | ||
| 210 | if lcfn<>'' then | ||
| 250 | if lcfn <> '' then | ||
| 211 | 251 | begin | |
| 212 | 252 | TranslateResourceStrings(UTF8ToSys(lcfn)); | |
| 213 | LCLPath:=ExtractFileName(lcfn); | ||
| 214 | Dot1:=pos('.',LCLPath); | ||
| 253 | LCLPath := ExtractFileName(lcfn); | ||
| 254 | Dot1 := pos('.', LCLPath); | ||
| 215 | 255 | ||
| 216 | if Dot1>1 then | ||
| 256 | if Dot1 > 1 then | ||
| 217 | 257 | begin | |
| 218 | Delete(LCLPath,1,Dot1-1); | ||
| 219 | LCLPath:=ExtractFilePath(lcfn)+'lcl'+LCLPath; | ||
| 258 | Delete(LCLPath, 1, Dot1 - 1); | ||
| 259 | LCLPath := ExtractFilePath(lcfn) + 'lcl' + LCLPath; | ||
| 220 | 260 | if FileExistsUTF8(LCLPath) then | |
| 221 | 261 | TranslateResourceStrings(UTF8ToSys(LCLPath)); | |
| 222 | 262 | end; | |
| 223 | 263 | ||
| 224 | LRSTranslator:=TDefaultTranslator.Create(lcfn); | ||
| 264 | LRSTranslator := TDefaultTranslator.Create(lcfn); | ||
| 225 | 265 | ||
| 226 | 266 | end; | |
| 227 | 267 |
tools/signipk
(48 / 0)
|   | |||
| 1 | #!/bin/sh -e | ||
| 2 | # | ||
| 3 | # signipk | ||
| 4 | # Copyright (C) 2010 Matthias Klumpp | ||
| 5 | # | ||
| 6 | # Authors: Matthias Klumpp <matthias@nlinux.org> | ||
| 7 | # | ||
| 8 | # This program is free software: you can redistribute it and/or modify | ||
| 9 | # it under the terms of the GNU General Public License as published by | ||
| 10 | # the Free Software Foundation, version 3 of the License. | ||
| 11 | # | ||
| 12 | # This program is distributed in the hope that it will be useful, | ||
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | # GNU General Public License for more details. | ||
| 16 | # | ||
| 17 | # You should have received a copy of the GNU General Public License | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | OPTION_SPEC="help,sign" | ||
| 20 | PARSED_OPTIONS=$(getopt -n "$0" -a -o hp: --l "$OPTION_SPEC" -- "$@") | ||
| 21 | |||
| 22 | eval set -- "$PARSED_OPTIONS" | ||
| 23 | |||
| 24 | function usage | ||
| 25 | { | ||
| 26 | echo "Usage:" | ||
| 27 | echo "signipk <options> [parameters]" | ||
| 28 | echo "Sign IPK packages using GPG." | ||
| 29 | } | ||
| 30 | |||
| 31 | if [ $? != 0 ] ; then usage ; exit 1 ; fi | ||
| 32 | |||
| 33 | INSTALL_DEV_FILES=1 | ||
| 34 | |||
| 35 | while true ; do | ||
| 36 | case "$1" in | ||
| 37 | -h|--help ) usage; exit 0;; | ||
| 38 | --sign ) SIGN=1; shift; ;; | ||
| 39 | -p ) case "$2" in | ||
| 40 | "") echo "No package specified!"; exit 3 ;; | ||
| 41 | *) export libtarget=$2 ; shift 2 ;; | ||
| 42 | esac ;; | ||
| 43 | --) shift ; break ;; | ||
| 44 | * ) echo "ERROR: unknown flag $1"; exit 2;; | ||
| 45 | esac | ||
| 46 | done | ||
| 47 | |||
| 48 | #Sign package here! |

