/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// create hex-value string from the MD5 value to keep // the string size minimal
OUStringBuffer buf( "SingleOfficeIPC_" ); for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) {
buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 );
} return buf.makeStringAndClear();
}
if (aResolver.fetchFileStatus(rFileURL) != osl::FileBase::E_None) returnfalse;
rTime = aResolver.m_aStatus.getModifyTime();
returntrue;
}
//Returns true if the Folder was more recently modified then //the lastsynchronized file. That is the repository needs to //be synchronized. bool compareExtensionFolderWithLastSynchronizedFile(
OUString const & folderURL, OUString const & fileURL)
{ bool bNeedsSync = false;
::osl::DirectoryItem itemExtFolder;
::osl::File::RC err1 =
::osl::DirectoryItem::get(folderURL, itemExtFolder); //If it does not exist, then there is nothing to be done if (err1 == ::osl::File::E_NOENT)
{ returnfalse;
} elseif (err1 != ::osl::File::E_None)
{
OSL_FAIL("Cannot access extension folder"); returntrue; //sync just in case
}
//If last synchronized does not exist, then OOo is started for the first time
::osl::DirectoryItem itemFile;
::osl::File::RC err2 = ::osl::DirectoryItem::get(fileURL, itemFile); if (err2 == ::osl::File::E_NOENT)
{ returntrue;
} elseif (err2 != ::osl::File::E_None)
{
OSL_FAIL("Cannot access file lastsynchronized"); returntrue; //sync just in case
}
//compare the modification time of the extension folder and the last //modified file
TimeValue timeFolder; if (getModifyTimeTargetFile(folderURL, timeFolder))
{
TimeValue timeFile; if (getModifyTimeTargetFile(fileURL, timeFile))
{ if (timeFile.Seconds < timeFolder.Seconds)
bNeedsSync = true;
} else
{
OSL_ASSERT(false);
bNeedsSync = true;
}
} else
{
OSL_ASSERT(false);
bNeedsSync = true;
}
bool office_is_running()
{ #ifdefined EMSCRIPTEN returntrue; #else //We need to check if we run within the office process. Then we must not use the pipe, because //this could cause a deadlock. This is actually a workaround for i82778
OUString sFile;
oslProcessError err = osl_getExecutableFile(& sFile.pData); bool ret = false; if (osl_Process_E_None == err)
{
sFile = sFile.copy(sFile.lastIndexOf('/') + 1); if ( #ifdefined _WIN32 //osl_getExecutableFile should deliver "soffice.bin" on windows //even if swriter.exe, scalc.exe etc. was started. This is a bug //in osl_getExecutableFile
sFile == "soffice.bin" || sFile == "soffice.exe" || sFile == "soffice.com"
|| sFile == "soffice" || sFile == "swriter.exe" || sFile == "swriter"
|| sFile == "scalc.exe" || sFile == "scalc" || sFile == "simpress.exe"
|| sFile == "simpress" || sFile == "sdraw.exe" || sFile == "sdraw"
|| sFile == "sbase.exe" || sFile == "sbase" #elifdefined MACOSX
sFile == "soffice" #elifdefined UNIX
sFile == "soffice.bin" #else #error"Unsupported platform" #endif
)
ret = true; else
ret = existsOfficePipe();
} else
{
OSL_FAIL("NOT osl_Process_E_None "); //if osl_getExecutable file then we take the risk of creating a pipe
ret = existsOfficePipe();
} return ret; #endif
}
oslProcess raiseProcess(
OUString const & appURL, Sequence<OUString> const & args )
{
::osl::Security sec;
oslProcess hProcess = nullptr;
oslProcessError rc = osl_executeProcess(
appURL.pData, reinterpret_cast<rtl_uString **>( const_cast<OUString *>(args.getConstArray()) ),
args.getLength(),
osl_Process_DETACHED,
sec.getHandle(),
nullptr, // => current working dir
nullptr, 0, // => no env vars
&hProcess );
switch (rc) { case osl_Process_E_None: break; case osl_Process_E_NotFound: throw RuntimeException( u"image not found!"_ustr, nullptr ); case osl_Process_E_TimedOut: throw RuntimeException( u"timeout occurred!"_ustr, nullptr ); case osl_Process_E_NoPermission: throw RuntimeException( u"permission denied!"_ustr, nullptr ); case osl_Process_E_Unknown: throw RuntimeException( u"unknown error!"_ustr, nullptr ); case osl_Process_E_InvalidError: default: throw RuntimeException( u"unmapped error!"_ustr, nullptr );
}
return hProcess;
}
OUString generateRandomPipeId()
{ // compute some good pipe id:
sal_uInt8 bytes[ 32 ]; if (rtl_random_getBytes(
nullptr, bytes, std::size(bytes) ) != rtl_Random_E_None) { throw RuntimeException( u"random pool error!?"_ustr, nullptr );
}
OUStringBuffer buf; for (unsignedchar byte : bytes) {
buf.append( static_cast<sal_Int32>(byte), 0x10 );
} return buf.makeStringAndClear();
}
OUString readConsole()
{ char buf[1024];
memset(buf, 0, 1024); // read one char less so that the last char in buf is always zero if (fgets(buf, 1024, stdin) != nullptr)
{
OUString value = OStringToOUString(std::string_view(buf), osl_getThreadTextEncoding()); return value.trim();
} throw css::uno::RuntimeException(u"reading from stdin failed"_ustr);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.