From 06d432b6c410154f5c4d3fb58d641d86f2acef04 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 24 Jun 2011 10:13:51 +0000 Subject: [PATCH] lazimageeditor: Adds a configuration file to implement resource file support in all platforms git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1720 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/lazimageeditor/aboutdialog.pas | 4 +- applications/lazimageeditor/appsettings.pas | 167 +++++++++++ .../lazimageeditor/build/build_package.sh | 264 ++++++++++++++++++ applications/lazimageeditor/install.sh | 31 ++ .../lazimageeditor/lazimageeditor.lpi | 23 +- .../lazimageeditor/lazimageeditor.pas | 3 +- applications/lazimageeditor/lieconstants.pas | 22 ++ 7 files changed, 509 insertions(+), 5 deletions(-) create mode 100644 applications/lazimageeditor/appsettings.pas create mode 100755 applications/lazimageeditor/build/build_package.sh create mode 100755 applications/lazimageeditor/install.sh create mode 100644 applications/lazimageeditor/lieconstants.pas diff --git a/applications/lazimageeditor/aboutdialog.pas b/applications/lazimageeditor/aboutdialog.pas index dccb0af05..a4d40a164 100644 --- a/applications/lazimageeditor/aboutdialog.pas +++ b/applications/lazimageeditor/aboutdialog.pas @@ -54,12 +54,12 @@ var implementation -uses IconStrConsts; +uses IconStrConsts, appsettings; { TAboutDialogForm } procedure TAboutDialogForm.FormCreate(Sender: TObject); begin - Image.Picture.LoadFromFile('.\Images\icon.png'); + Image.Picture.LoadFromFile(vConfigurations.MyDirectory + 'Images' + PathDelim + 'icon.png'); Caption:=lieAbouDialog; LabelVersion.Caption:=lieLabelVersion; LabelAuthor.Caption:=lieLabelAuthor; diff --git a/applications/lazimageeditor/appsettings.pas b/applications/lazimageeditor/appsettings.pas new file mode 100644 index 000000000..e37325ff9 --- /dev/null +++ b/applications/lazimageeditor/appsettings.pas @@ -0,0 +1,167 @@ +{ + *************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at . You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * + *************************************************************************** + + Author: Felipe Monteiro de Carvalho + + Abstract: + Unit to control the custom configurations of the application +} +unit appsettings; + +{$MODE DELPHI} + +interface + +uses +{$IFDEF Windows} + Windows, shlobj, +{$ENDIF} + Classes, SysUtils, Forms, IniFiles, lieconstants; + +type + { TConfigurations } + + TConfigurations = class(TObject) + private + ConfigFilePath: string; + public + MyDirectory: string; + Language: Integer; + constructor Create; + destructor Destroy; override; + procedure ReadFromFile(Sender: TObject); + procedure Save(Sender: TObject); + function GetConfigFilePath: string; + function GetMyDirectory: string; + end; + +var + vConfigurations: TConfigurations; + +implementation + +{$ifdef Darwin} +uses + MacOSAll; +{$endif} + +{ TConfigurations } + +constructor TConfigurations.Create; +begin + { First we use some good defaults in case the configuration file doesn't yet exist } + +// Language := GetSystemLanguage(); + + { Now identifies where the configuration file should be } + ConfigFilePath := GetConfigFilePath(); + + // Under Mac OS X we need to get the location of the bundle + MyDirectory := GetMyDirectory(); + + ReadFromFile(nil); +end; + +destructor TConfigurations.Destroy; +begin + Save(nil); + + inherited Destroy; +end; + +procedure TConfigurations.ReadFromFile(Sender: TObject); +var + MyFile: TIniFile; +begin + if not FileExists(ConfigFilePath) then Exit; + + MyFile := TIniFile.Create(ConfigFilePath); + try + Language := MyFile.ReadInteger(SectionGeneral, IdentLanguage, 0); + + {$ifdef UNIX}{$ifndef DARWIN} + MyDirectory := MyFile.ReadString(SectionUnix, IdentMyDirectory, DefaultDirectory); + {$endif}{$endif} + finally + MyFile.Free; + end; +end; + +procedure TConfigurations.Save(Sender: TObject); +var + MyFile: TIniFile; +begin + MyFile := TIniFile.Create(ConfigFilePath); + try + MyFile.WriteInteger(SectionGeneral, IdentLanguage, Language); + + MyFile.WriteString(SectionUnix, IdentMyDirectory, MyDirectory); + finally + MyFile.Free; + end; +end; + +function TConfigurations.GetConfigFilePath: string; +begin +{$ifdef Windows} + // First tryes to use a configuration file in the application directory + Result := ExtractFilePath(Application.EXEName) + 'magnifier.ini'; +{$endif} +{$ifdef Unix} + Result := GetEnvironmentVariable('HOME') + '/.magnifier.ini'; +{$endif} +end; + +function TConfigurations.GetMyDirectory: string; +{$ifdef Darwin} +var + pathRef: CFURLRef; + pathCFStr: CFStringRef; + pathStr: shortstring; +{$endif} +begin +{$ifdef UNIX} +{$ifdef Darwin} + pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle()); + pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle); + CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding()); + CFRelease(pathRef); + CFRelease(pathCFStr); + + Result := pathStr + BundleResourcesDirectory; +{$else} + Result := DefaultDirectory; +{$endif} +{$endif} + +{$ifdef Windows} + Result := ExtractFilePath(Application.EXEName); +{$endif} +end; + +initialization + + vConfigurations := TConfigurations.Create; + +finalization + + FreeAndNil(vConfigurations); + +end. diff --git a/applications/lazimageeditor/build/build_package.sh b/applications/lazimageeditor/build/build_package.sh new file mode 100755 index 000000000..5b3d51f2e --- /dev/null +++ b/applications/lazimageeditor/build/build_package.sh @@ -0,0 +1,264 @@ +#!/bin/sh +# +# This script generates packages for the Lazarus Image Editor +# + +################################## +# Constants +################################## + +PRODUCT="Lazarus Image Editor" +VERSION="1.0" +OS="linux" +EXENAME="lazimageeditor" + +TARGET_DIR="./$EXENAME-$OS-$VERSION" +TARGET_TAR="$EXENAME-$OS-$VERSION.tar" +TARGET_ZIP="$EXENAME-$VERSION.zip" + +# DEBIAN_USR_DIR=/home/felipe/Programas/magnifier/build/usr + +################################## +# Builds a binary tar package +################################## +BuildBinary () +{ + # Goes to the root directory + + cd .. + + # Builds the software + +# ~/Programas/lazarus/lazbuild $EXENAME.lpi + + strip --strip-all $EXENAME + + # Creates main directory + + mkdir $TARGET_DIR/ + mkdir $TARGET_DIR/Images + + # Copies files to the directory + + cp ./$EXENAME $TARGET_DIR/ + cp ./install.sh $TARGET_DIR/ + cp ./Images/*.png $TARGET_DIR/Images/ + + # Creates the archive + + tar -cvf $TARGET_TAR $TARGET_DIR/ + + bzip2 $TARGET_TAR + + # Clean up + + rm -rf $TARGET_DIR/ + + cd build + + return +} + + +################################## +# Creates a source zip package +################################## +SourcePackage () +{ + # Goes to the root directory of the magnifier + + cd .. + + # Clean up + + echo "Clean up" + ./clean.sh + rm -rf ../magnifier-$VERSION/ + + # We use SVN export to get rid of the heavy svn files + # copies all files to a new temporary directory + + echo "svn export ./ ../magnifier-$VERSION/" + svn export ./ ../magnifier-$VERSION/ + + # Creates the package + + echo "zip -r ../$TARGET_ZIP ../magnifier-$VERSION/" + zip -rv ../$TARGET_ZIP ../magnifier-$VERSION/ + + # Clean up + + echo "Clean up" + rm -rf ../magnifier-$VERSION/ + cd build + + return +} + +################################## +# Set up the RPM build environment +################################## +CreateRPMEnvironment () +{ + # Creates the directory structure + + mkdir $HOME/RPM + mkdir $HOME/RPM/BUILD # This directory is utilized by RPM to build the package. + mkdir $HOME/RPM/RPMS # Here you can find binary RPMs after you build them. + mkdir $HOME/RPM/SOURCES # Place your compressed tar files and patches here. + mkdir $HOME/RPM/SPECS # Place all your spec files here. + mkdir $HOME/RPM/SRPMS # Here you can find source RPMs after you build them. + + # rpmbuild environment file + + touch $HOME/.rpmmacros + + echo "%_topdir /home/felipe/RPM/" >> $HOME/.rpmmacros + echo "%_tmppath /home/felipe/tmp" >> $HOME/.rpmmacros + echo "" >> $HOME/.rpmmacros + echo "%_signature gpg" >> $HOME/.rpmmacros + echo "%_gpg_name Mandrakelinux" >> $HOME/.rpmmacros + echo "%_gpg_path ~/.gnupg" >> $HOME/.rpmmacros + + # Spec file + + cp magnifier.spec $HOME/RPM/SPECS/ + + # Zip file + + cp ../../$TARGET_ZIP $HOME/RPM/SOURCES/ + + return +} + +################################## +# Builds a binary and source RPM package +################################## +RPMPackage () +{ + # Set up the RPM build environment + CreateRPMEnvironment + + # now build it + echo "rpmbuild -ba --clean $HOME/RPM/SPECS/magnifier.spec" + rpmbuild -ba --clean $HOME/RPM/SPECS/magnifier.spec + + return +} + +################################## +# Creates a Debian package +################################## +DebianPackage () +{ + # Goes to the root directory of the magnifier + + cd .. + + # Builds the software + +# ./make.sh + + strip --strip-all magnifier + + # Returns to build dir + + cd build + + # Creates the control.tar.gz file + + tar -cvf control.tar control + + gzip control.tar + + # Creates the data.tar.gz file + + mkdir $DEBIAN_USR_DIR + mkdir $DEBIAN_USR_DIR/bin + mkdir $DEBIAN_USR_DIR/share + mkdir $DEBIAN_USR_DIR/share/magnifier + + cd .. + + cp ./magnifier $DEBIAN_USR_DIR/bin/vmg + + cp $RESOURCES $DEBIAN_USR_DIR/share/magnifier + + cd $MANUALS_DIR + + cp $MANUALS $DEBIAN_USR_DIR/share/magnifier + + cd .. + + cd build + + tar -cvf data.tar $DEBIAN_USR_DIR + + gzip data.tar + + # Creates the package + + mkdir DEBIAN + + cp control DEBIAN/ + cp data.tar.gz DEBIAN/ + cp debian-binary DEBIAN/ + + dpkg -b ./ magnifier_3.4-0_i386.deb + + # Clean up + + echo "Clean up" + + rm -rf $DEBIAN_USR_DIR + + rm -rf ./DEBIAN + + rm -rf data.tar.gz + + rm -rf control.tar.gz + + cd .. + + ./clean.sh + + cd build + + return +} + + +################################## +# Main section +################################## + +echo "========================================================" +echo " Lazarus Image Editor build script" +echo "========================================================" +echo "" +echo " Please select which package you would like to build:" +echo "" +echo " 1 > Linux Gtk2 binary tar.bz2 package" +echo " 3 > Source .zip package" +echo " 4 > RPM package (source and binary)" +echo " 5 > Debian package" +echo " 0 > Exit" + +read command + +case $command in + + 1) BuildBinary;; + + 3) SourcePackage;; + + 4) RPMPackage;; + + 5) DebianPackage;; + + 0) exit 0;; + + *) echo "Invalid command" + exit 0;; + +esac diff --git a/applications/lazimageeditor/install.sh b/applications/lazimageeditor/install.sh new file mode 100755 index 000000000..5ccdbb584 --- /dev/null +++ b/applications/lazimageeditor/install.sh @@ -0,0 +1,31 @@ +# +# Parses command line options. Currently supported options are: +# +# DESTDIR Destination root directory +# + +DESTDIR="" +EXENAME="lazimageeditor" + +for arg; do + + case $arg in + + DESTDIR=*) DESTDIR=${arg#DESTDIR=};; + + esac; + +done + +# +# Does the install +# + +mkdir -p $DESTDIR/usr/share/$EXENAME +mkdir -p $DESTDIR/usr/share/$EXENAME/Images + +cp ./Images/*.png $DESTDIR/usr/share/$EXENAME/Images/ + +mkdir -p $DESTDIR/usr/bin + +cp ./$EXENAME $DESTDIR/usr/bin/$EXENAME diff --git a/applications/lazimageeditor/lazimageeditor.lpi b/applications/lazimageeditor/lazimageeditor.lpi index b91f40879..f78b7b797 100644 --- a/applications/lazimageeditor/lazimageeditor.lpi +++ b/applications/lazimageeditor/lazimageeditor.lpi @@ -27,6 +27,7 @@ + @@ -42,7 +43,7 @@ - + @@ -123,6 +124,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/applications/lazimageeditor/lazimageeditor.pas b/applications/lazimageeditor/lazimageeditor.pas index 408165dee..74b18a473 100644 --- a/applications/lazimageeditor/lazimageeditor.pas +++ b/applications/lazimageeditor/lazimageeditor.pas @@ -16,7 +16,7 @@ uses ResizeDialog, ResizePaperDialog, PictureDialog, - AboutDialog, DLBitmap; + AboutDialog, DLBitmap, IconStrConsts, appsettings, lieconstants, ColorPalette; {$R *.res} @@ -35,7 +35,6 @@ begin MainForm.OpenImageFile(ParamStr(1)) else MainForm.FileNewOnStart; - Application.Run; end. diff --git a/applications/lazimageeditor/lieconstants.pas b/applications/lazimageeditor/lieconstants.pas new file mode 100644 index 000000000..fcbc63ccb --- /dev/null +++ b/applications/lazimageeditor/lieconstants.pas @@ -0,0 +1,22 @@ +unit lieconstants; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils; + +const + DefaultDirectory = '/usr/share/lazimageeditor/'; + + SectionGeneral = 'General'; + IdentLanguage = 'Language'; + + SectionUNIX = 'UNIX'; + IdentMyDirectory = 'MyDirectory'; + +implementation + +end. +