19#include <com/sun/star/lang/XMultiServiceFactory.hpp>
20#include <com/sun/star/ucb/UniversalContentBroker.hpp>
21#include <com/sun/star/frame/Desktop.hpp>
26#include <osl/file.hxx>
27#include <osl/process.h>
45 GalApp() : mbInBuildTree( false ), mbRelativeURLs( false )
48 virtual int Main()
override;
51 uno::Reference<lang::XMultiServiceFactory> xMSF;
58static void createTheme(
const OUString& aThemeName, std::u16string_view aGalleryURL,
59 const OUString& aDestDir, std::vector<INetURLObject> &rFiles,
62 std::unique_ptr<Gallery> pGallery(
new Gallery( aGalleryURL ));
64 fprintf( stderr,
"Work on gallery '%s'\n",
68 pGallery->GetThemeCount() );
71 if( !pGallery->HasTheme( aThemeName) ) {
72 if( !pGallery->CreateTheme( aThemeName ) ) {
73 fprintf( stderr,
"Failed to create theme\n" );
79 pGallery->GetThemeCount() );
83 pGalTheme = pGallery->AcquireTheme( aThemeName, aListener );
85 fprintf( stderr,
"Failed to acquire theme\n" );
89 fprintf( stderr,
"Using DestDir: %s\n",
91 pGalTheme->
SetDestDir( aDestDir, bRelativeURLs );
93 for(
const auto& rFile : rFiles )
100 fprintf( stderr,
"Failed to import '%s'\n",
103 fprintf( stderr,
"Imported file '%s' (%" SAL_PRIuUINT32
")\n",
108 pGallery->ReleaseTheme( pGalTheme, aListener );
113 fprintf( stdout,
"Utility to generate LibreOffice gallery files\n\n" );
115 fprintf( stdout,
"using: gengal --name <name> --path <dir> [ --destdir <path> ]\n");
116 fprintf( stdout,
" [ files ... ]\n\n" );
118 fprintf( stdout,
"options:\n");
119 fprintf( stdout,
" --name <theme>\t\tdefines the user visible name of the created or updated theme.\n");
121 fprintf( stdout,
" --path <dir>\t\tdefines directory where the gallery files are created\n");
122 fprintf( stdout,
"\t\t\tor updated.\n");
124 fprintf( stdout,
" --destdir <dir>\tdefines a path prefix to be removed from the paths\n");
125 fprintf( stdout,
"\t\t\tstored in the gallery files. It is useful to create\n");
126 fprintf( stdout,
"\t\t\tRPM packages using the BuildRoot feature.\n");
128 fprintf( stdout,
" --relative-urls\t\tflags that after removing the destdir, the URL should be a path relative to the gallery folder in the install\n");
129 fprintf( stdout,
"\t\t\tprimarily used for internal gallery generation at compile time.\n");
130 fprintf( stdout,
"\t\t\ttheme files.\n");
131 fprintf( stdout,
" files\t\t\tlists files to be added to the gallery. Absolute paths\n");
132 fprintf( stdout,
"\t\t\tare required.\n");
141 aURL.SetSmartURL( rPath );
148 if( !mbInBuildTree && getenv(
"OOO_INSTALL_PREFIX" ) ==
nullptr ) {
149 OUString fileName = GetAppFileName();
150 int lastSlash = fileName.lastIndexOf(
'/' );
154 if( fileName.lastIndexOf(
'\\' ) > lastSlash )
155 lastSlash = fileName.lastIndexOf(
'\\' );
157 OUString baseBinDir = fileName.copy( 0, lastSlash );
158 OUString installPrefix = baseBinDir +
"/../..";
160 OUString envVar(
"OOO_INSTALL_PREFIX");
161 osl_setEnvironment(envVar.pData, installPrefix.pData);
163 SAL_INFO(
"svx",
"OOO_INSTALL_PREFIX=" << getenv(
"OOO_INSTALL_PREFIX" ) );
165 uno::Reference<uno::XComponentContext> xComponentContext
166 = ::cppu::defaultBootstrap_InitialComponentContext();
167 xMSF.set( xComponentContext->getServiceManager(), uno::UNO_QUERY );
170 fprintf( stderr,
"Failed to bootstrap\n" );
173 ::comphelper::setProcessServiceFactory( xMSF );
177 css::ucb::UniversalContentBroker::create(xComponentContext);
178 }
catch (
const uno::Exception &e) {
179 fprintf( stderr,
"Bootstrap exception '%s'\n",
187 osl::File file(rInput);
188 osl::FileBase::RC rc = file.open(osl_File_OpenFlag_Read);
190 if (osl::FileBase::E_None != rc)
192 fprintf(stderr,
"error while opening response file: %s (%d)\n",
193 uInput.getStr(), rc);
197 std::vector<OUString> ret;
198 OUStringBuffer b(256);
203 rc = file.read(buf,
sizeof(buf),
size);
204 if (osl::FileBase::E_None != rc)
206 fprintf(stderr,
"error while reading response file: %s (%d)\n",
207 uInput.getStr(), rc);
212 for (sal_uInt64
i = 0;
i <
size; ++
i)
214 if (
static_cast<unsigned char>(buf[
i]) >= 128)
216 fprintf(stderr,
"non-ASCII character in response file: %s\n",
227 ret.push_back(b.makeStringAndClear());
236 ret.push_back(b.makeStringAndClear());
244 for (
size_t i = 0;
i < files.size(); ++
i)
256 OUString aPath, aDestDir;
257 OUString
aName(
"Default name" );
258 std::vector<INetURLObject> aFiles;
260 for( sal_uInt16 i = 0;
i < GetCommandLineParamCount(); ++
i )
262 OUString aParam = GetCommandLineParam( i );
264 if ( aParam.startsWith(
"-env:" ) )
266 else if ( aParam ==
"--help" || aParam ==
"-h" )
268 else if ( aParam ==
"--build-tree" )
270 mbRelativeURLs =
true;
271 mbInBuildTree =
true;
273 else if ( aParam ==
"--name" )
274 aName = GetCommandLineParam( ++i );
275 else if ( aParam ==
"--path" )
276 aPath =
Smartify( GetCommandLineParam( ++i ) ).
278 else if ( aParam ==
"--destdir" )
279 aDestDir = GetCommandLineParam( ++i );
280 else if ( aParam ==
"--relative-urls" )
281 mbRelativeURLs =
true;
282 else if ( aParam ==
"--number-from" )
283 fprintf ( stderr,
"--number-from is deprecated, themes now "
284 "have filenames based on their names\n" );
285 else if ( aParam ==
"--filenames" )
288 aFiles.push_back(
Smartify( aParam ) );
294 createTheme( aName, aPath, aDestDir, aFiles, mbRelativeURLs );
296 catch (
const uno::Exception&)
301 catch (
const std::exception &e)
303 SAL_WARN(
"svx",
"Fatal: " << e.what());
313 xDesktop->terminate();
314 uno::Reference< lang::XComponent >(
316 uno::UNO_QUERY_THROW )->
dispose();
317 ::comphelper::setProcessServiceFactory(
nullptr );
323 static GalApp aGalApp;
static void EnableConsoleOnly()
bool InsertURL(const INetURLObject &rURL, sal_uInt32 nInsertPos=SAL_MAX_UINT32)
void SetDestDir(const OUString &rDestDir, bool bRelative)
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
static SfxApplication * GetOrCreate()
#define TOOLS_WARN_EXCEPTION(area, stream)
static std::vector< OUString > ReadResponseFile_Impl(OUString const &rInput)
static INetURLObject Smartify(std::u16string_view rPath)
static void createTheme(const OUString &aThemeName, std::u16string_view aGalleryURL, const OUString &aDestDir, std::vector< INetURLObject > &rFiles, bool bRelativeURLs)
static void ReadResponseFile(std::vector< INetURLObject > &rFiles, OUString const &rInput)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
Reference< XComponentContext > getProcessComponentContext()
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)