summaryrefslogtreecommitdiff
path: root/chart2/workbench/officeintegration/install.pl
blob: 8ae93e3f91858ad6de3aa2c175f7859d9cea049f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
:
eval 'exec perl -S $0 ${1+"$@"}'
    if 0;

# ------------------------------------------------------------------------------
# This script installs the new chart-libraries and resources.
# This is done by symbolic linking rather than copying.  Thus this installation
# is only necessary once after a fresh office installation.
#
# It also registers all types in the types.rdb and all components in the
# services.rdb.  Finally the TypeDetection.xcu is installed, such that you can
# invoke the new chart with the URL 'private:factory/chart'
# ------------------------------------------------------------------------------

# With this package you get better readable variable names
use English;

# determine automatic project path assuming that this script stayed in its
# default location

$PRJ_PATH = $0;
if( $OSNAME eq "MSWin32" ) {
    chomp( $PRJ_PATH = `cd` );
    $PRJ_PATH =~ s,^(.*)\\workbench\\?.*$,$1,;

    $SVERSION = "$ENV{UserProfile}\\Application Data\\sversion.ini";
    $PATHSEP = "\\";
    $LIBPATTERN = "bin\\*mi*.dll";
    $COPYCMD = "copy";
} else {
    chomp( $PRJ_PATH = `pwd` );
    $PRJ_PATH = $PWD . "/" . $PRJ_PATH if( $PRJ_PATH !~ m,^/, );
    $PRJ_PATH =~ s,^(.*)/workbench/?.*$,$1,;

    $SVERSION = "$ENV{HOME}/.sversionrc";
    $PATHSEP = "/";
    $LIBPATTERN = "lib/lib*.so";
    $COPYCMD = "cp";
}

# determine office path according to .sversionrc. Note: this only looks for a
# prefix 'StarOffice 8', such that 'StarOffice 8 dbg=...' is still found
# if no 'StarOffice 8' was found, 'OpenOffice.org 2' is searched for

open( SVERSION, "$SVERSION" ) || die( "couldn't find .sversionrc/sversion.ini\n" );
while( <SVERSION> )
{
    if( m,^StarOffice 8.*=file://(.*)$, )
    {
        $OFF_PATH = $1,;
        if( $OSNAME eq "MSWin32" )
        {
            # remove first /
            $OFF_PATH =~ s/^.//;
            # replace path separators
            $OFF_PATH =~ s,/,\\,g;
        }
        last;
    }
    elsif ( m,^OpenOffice.org 2.*=file://(.*)$, )
    {
        $OFF_PATH = $1,;
        if( $OSNAME eq "MSWin32" )
        {
            # remove first /
            $OFF_PATH =~ s/^.//;
            # replace path separators
            $OFF_PATH =~ s,/,\\,g;
        }
        last;
    }
}
close SVERSION;

$USER_PATH = "$OFF_PATH${PATHSEP}user";

# ================================================================================

print "Chart2 project is in <$PRJ_PATH>\n";
print "OpenOffice.org 2.0/StarOffice 8 is installed in <$OFF_PATH>\n";
print "Are these assumptions correct? [y/n] ";
if( <STDIN> !~ /^y?$/i )
{
    print "Enter project path [$PRJ_PATH]: ";
    chomp( $path = <STDIN> );
    $PRJ_PATH = $path if( length( $path ) > 0 );

    print "Enter office path [$OFF_PATH]: ";
    chomp( $path = <STDIN> );
    $OFF_PATH = $path if( length( $path ) > 0 );
}

# ----------------------------------------

$MY_OUTPATH = $ENV{OUTPATH};
$MY_RESPATH = "common";

$REGCOMMAND = "register";
#$REGCOMMAND = "revoke";

if( $ENV{PROEXT} ) {
    $MY_OUTPATH .= $ENV{PROEXT};
    $MY_RESPATH .= $ENV{PROEXT};
}

chmod 0664, "$OFF_PATH${PATHSEP}program${PATHSEP}types.rdb";
print "registering types...\n";
print `regmerge $OFF_PATH${PATHSEP}program${PATHSEP}types.rdb / $PRJ_PATH${PATHSEP}$MY_OUTPATH${PATHSEP}bin${PATHSEP}chart2.rdb`;

print "installing shlibs and registering services...\n";
@files = glob( "$PRJ_PATH${PATHSEP}$MY_OUTPATH${PATHSEP}${LIBPATTERN}" );
foreach $dll (@files)
{
    if( $OSNAME eq "MSWin32" ) {
        print `copy "$dll" "$OFF_PATH\\program"`;
        $dll =~ s,\\,/,g;
        $dll =~ m,/([^/]*)$,;
        $copied_dll = "/$dll";
    } else {
        $dll =~ m,/([^/]*)$,;
        $copied_dll = "$OFF_PATH/program/$1";
        if( -l "$copied_dll" ) {
            unlink "$copied_dll";
        }
        symlink "$dll", "$copied_dll";
    }
    chmod 0664, "$OFF_PATH${PATHSEP}program${PATHSEP}services.rdb";
    print `regcomp -$REGCOMMAND -r $OFF_PATH${PATHSEP}program${PATHSEP}services.rdb -c file://$copied_dll`;
    print `regcomp -$REGCOMMAND -r $OFF_PATH${PATHSEP}program${PATHSEP}types.rdb -c file://$copied_dll`;
}

print "installing resources\n";
@files = glob( "$PRJ_PATH${PATHSEP}$MY_RESPATH${PATHSEP}bin${PATHSEP}*.res" );
foreach $res (@files)
{
    if( $OSNAME eq "MSWin32" ) {
        print `copy "$res" "$OFF_PATH\\program\\resource"`;
    } else {
        $res =~ m,/([^/]*)$,;
        $copied_res = "$OFF_PATH/program/resource/$1";
        if( -l "$copied_dll" ) {
            unlink "$copied_res";
        }
        symlink "$res", "$copied_res";
    }
}