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
This commit is contained in:
sekelsenmat
2011-06-24 10:13:51 +00:00
parent 2cb9e11e9b
commit 06d432b6c4
7 changed files with 509 additions and 5 deletions

View File

@ -54,12 +54,12 @@ var
implementation implementation
uses IconStrConsts; uses IconStrConsts, appsettings;
{ TAboutDialogForm } { TAboutDialogForm }
procedure TAboutDialogForm.FormCreate(Sender: TObject); procedure TAboutDialogForm.FormCreate(Sender: TObject);
begin begin
Image.Picture.LoadFromFile('.\Images\icon.png'); Image.Picture.LoadFromFile(vConfigurations.MyDirectory + 'Images' + PathDelim + 'icon.png');
Caption:=lieAbouDialog; Caption:=lieAbouDialog;
LabelVersion.Caption:=lieLabelVersion; LabelVersion.Caption:=lieLabelVersion;
LabelAuthor.Caption:=lieLabelAuthor; LabelAuthor.Caption:=lieLabelAuthor;

View File

@ -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 <http://www.gnu.org/copyleft/gpl.html>. 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.

View File

@ -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

View File

@ -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

View File

@ -27,6 +27,7 @@
<RunParams> <RunParams>
<local> <local>
<FormatVersion Value="1"/> <FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="\usr\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local> </local>
</RunParams> </RunParams>
<RequiredPackages Count="3"> <RequiredPackages Count="3">
@ -42,7 +43,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item3> </Item3>
</RequiredPackages> </RequiredPackages>
<Units Count="12"> <Units Count="16">
<Unit0> <Unit0>
<Filename Value="lazimageeditor.pas"/> <Filename Value="lazimageeditor.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -123,6 +124,26 @@
<Filename Value="DLBmpUtils.inc"/> <Filename Value="DLBmpUtils.inc"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit11> </Unit11>
<Unit12>
<Filename Value="iconstrconsts.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="IconStrConsts"/>
</Unit12>
<Unit13>
<Filename Value="appsettings.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="appsettings"/>
</Unit13>
<Unit14>
<Filename Value="lieconstants.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="lieconstants"/>
</Unit14>
<Unit15>
<Filename Value="colorpalette.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ColorPalette"/>
</Unit15>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -16,7 +16,7 @@ uses
ResizeDialog, ResizeDialog,
ResizePaperDialog, ResizePaperDialog,
PictureDialog, PictureDialog,
AboutDialog, DLBitmap; AboutDialog, DLBitmap, IconStrConsts, appsettings, lieconstants, ColorPalette;
{$R *.res} {$R *.res}
@ -35,7 +35,6 @@ begin
MainForm.OpenImageFile(ParamStr(1)) MainForm.OpenImageFile(ParamStr(1))
else else
MainForm.FileNewOnStart; MainForm.FileNewOnStart;
Application.Run; Application.Run;
end. end.

View File

@ -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.