1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
9 * last change: $Author:$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
44 #define INCL_DOSERRORS
48 // OOo uses popen() to start us, so we cannot show PM dialogs.
49 // log message to disk.
50 void logMessage( char* msg
)
53 CHAR szApplicationName
[_MAX_PATH
];
54 CHAR szDrive
[_MAX_PATH
];
55 CHAR szDir
[_MAX_PATH
];
56 CHAR szFileName
[_MAX_PATH
];
57 CHAR szExt
[_MAX_PATH
];
62 // get executable fullpath
63 DosGetInfoBlocks(NULL
, &pib
);
64 DosQueryModuleName(pib
->pib_hmte
, sizeof(szApplicationName
), szApplicationName
);
65 _splitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
67 _makepath( szApplicationName
, szDrive
, szDir
, szFileName
, (".LOG") );
68 log
= fopen( szApplicationName
, "a");
72 localTime
= localtime( &timeOfDay
);
73 fprintf( log
, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
74 localTime
->tm_year
+1900, localTime
->tm_mon
+1, localTime
->tm_mday
,
75 localTime
->tm_hour
, localTime
->tm_min
, localTime
->tm_sec
, msg
);
79 // dump comand line arguments
80 void dumpArgs( int argc
, char *argv
[] )
84 logMessage( "Start of command line arguments dump:");
85 for( i
=0; i
<argc
; i
++)
90 * The intended use of this tool is to pass the argument to
91 * the default URL exe.
93 int main(int argc
, char *argv
[] )
96 RESULTCODES result
= {0};
97 char szAppFromINI
[_MAX_PATH
];
98 char szDirFromINI
[_MAX_PATH
];
100 char szFail
[ _MAX_PATH
];
107 logMessage( "Usage: open-url <url>");
108 dumpArgs( argc
, argv
);
112 // check configuration
113 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
114 "DefaultBrowserExe", "",
115 szAppFromINI
, sizeof(szAppFromINI
));
116 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
117 "DefaultWorkingDir", "",
118 szDirFromINI
, sizeof(szDirFromINI
));
119 if (*szAppFromINI
== 0 || *szDirFromINI
== 0)
121 logMessage( "Unable to find default url handler in USER.INI; exiting.");
122 dumpArgs( argc
, argv
);
126 // get default parameter list
127 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
128 "DefaultParameters", "",
129 szCmdLine
, sizeof(szCmdLine
));
130 strcat( szCmdLine
, " ");
131 strcat( szCmdLine
, argv
[1]);
133 // change default directory
134 _chdir( szDirFromINI
);
136 // start default handler
138 CHAR szObjBuf
[CCHMAXPATH
];
140 SData
.Length
= sizeof(STARTDATA
);
141 SData
.Related
= SSF_RELATED_INDEPENDENT
;
142 SData
.FgBg
= (1) ? SSF_FGBG_FORE
: SSF_FGBG_BACK
;
143 SData
.TraceOpt
= SSF_TRACEOPT_NONE
;
145 SData
.PgmTitle
= (PSZ
)szAppFromINI
;
147 SData
.PgmName
= (PSZ
)szAppFromINI
;
148 SData
.PgmInputs
= (PSZ
)szCmdLine
;
151 SData
.Environment
= 0;
152 SData
.InheritOpt
= SSF_INHERTOPT_PARENT
;
153 SData
.SessionType
= SSF_TYPE_PM
;
157 SData
.PgmControl
= SSF_CONTROL_VISIBLE
;
161 SData
.InitXSize
= 200;
162 SData
.InitYSize
= 140;
164 SData
.ObjectBuffer
= szFail
;
165 SData
.ObjectBuffLen
= (ULONG
)sizeof(szFail
);
167 rc
= DosStartSession( &SData
, &ulSID
, &pid
);
168 // show error dialog in case of problems
169 if (rc
!= NO_ERROR
&& rc
!= ERROR_SMG_START_IN_BACKGROUND
) {
170 char szMessage
[ _MAX_PATH
*2];
171 sprintf( szMessage
, "Execution failed! rc: %d, failing module:%s", rc
, szFail
);
172 logMessage( szMessage
);
173 dumpArgs( argc
, argv
);