16#include <com/sun/star/io/IOException.hpp>
17#include <com/sun/star/io/XOutputStream.hpp>
18#include <com/sun/star/io/XInputStream.hpp>
19#include <com/sun/star/ucb/XCommandEnvironment.hpp>
25bool isWordFormat(std::u16string_view sExt)
32bool isExcelFormat(std::u16string_view sExt)
38bool isPowerPointFormat(std::u16string_view sExt)
45OUString GenerateMSOLockFileURL(std::u16string_view aOrigURL)
50 OUString sFileName =
aURL.GetLastName();
51 const OUString sExt =
aURL.GetFileExtension();
53 if (isWordFormat(sExt))
55 const sal_Int32 nFileNameLength = sFileName.getLength() - sExt.getLength() - 1;
56 if (nFileNameLength >= 8)
57 sFileName = sFileName.copy(2);
58 else if (nFileNameLength == 7)
59 sFileName = sFileName.copy(1);
61 aURL.setName(Concat2View(
"~$" + sFileName));
72 if (isWordFormat(sExt))
74 else if (isExcelFormat(sExt))
82 , m_eAppType(getAppType(aOrigURL))
90 const css::uno::Reference<css::io::XOutputStream>& xOutput)
95 css::uno::Sequence<sal_Int8>
aData(nLockFileSize);
110 for (
int nChar = 0; nChar < aUserName.getLength(); ++nChar)
147 for (
int nChar = 0; nChar < aUserName.getLength(); ++nChar)
159 while (
nIndex < nLockFileSize)
167 while (
nIndex < nLockFileSize)
171 if (
nIndex < nLockFileSize)
180 xOutput->writeBytes(
aData);
183css::uno::Reference<css::io::XInputStream>
186 css::uno::Reference<css::ucb::XCommandEnvironment> xEnv;
196 css::uno::Reference<css::io::XInputStream> xInput =
OpenStream(rGuard);
198 throw css::uno::RuntimeException();
200 const sal_Int32 nBufLen = 256;
201 css::uno::Sequence<sal_Int8>
aBuf(nBufLen);
202 const sal_Int32 nRead = xInput->readBytes(
aBuf, nBufLen);
203 xInput->closeInput();
218 const int nACPLen =
aBuf[0];
219 if (nACPLen > 0 && nACPLen <= 52)
222 int nUTF16Len = *pBuf;
226 if (nUTF16Len == 0x20 && (*(pBuf - 1) != 0 || *(pBuf - 2) != 0))
229 if (nUTF16Len > 0 && nUTF16Len <= 52)
231 OUStringBuffer str(nUTF16Len);
233 for (
int i = 0;
i != nUTF16Len; ++
i)
254 throw css::io::IOException();
264 return isWordFormat(sExt) || isExcelFormat(sExt) || isPowerPointFormat(sExt);
OUString GetFileExtension() const
Generalized class for LO and MSO lockfile handling.
void RemoveFileDirectly()
Only delete lockfile, disregarding ownership.
static LockFileEntry GenerateOwnEntry()
const OUString & GetURL() const
static INetURLObject ResolveLinks(const INetURLObject &aDocURL)
virtual void WriteEntryToStream(std::unique_lock< std::mutex > &rGuard, const LockFileEntry &aEntry, const css::uno::Reference< css::io::XOutputStream > &xStream) override
virtual ~MSODocumentLockFile() override
virtual css::uno::Reference< css::io::XInputStream > OpenStream(std::unique_lock< std::mutex > &rGuard) override
virtual void RemoveFile() override
Delete the Lockfile, if current user is the owner.
MSODocumentLockFile(std::u16string_view aOrigURL)
static bool IsMSOSupportedFileFormat(std::u16string_view aURL)
static AppType getAppType(std::u16string_view sOrigURL)
virtual LockFileEntry GetLockDataImpl(std::unique_lock< std::mutex > &rGuard) override
css::uno::Reference< css::io::XInputStream > openStreamNoLock()
std::unique_ptr< sal_Int32[]> pData
#define MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE
#define MSO_WORD_LOCKFILE_SIZE
#define MSO_USERNAME_MAX_LENGTH
constexpr OUStringLiteral aData
Reference< XComponentContext > getProcessComponentContext()
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)