LibreOffice Module unotools (master)
1
unotools
source
ucbhelper
localfilehelper.cxx
Go to the documentation of this file.
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
* This file is part of the LibreOffice project.
4
*
5
* This Source Code Form is subject to the terms of the Mozilla Public
6
* License, v. 2.0. If a copy of the MPL was not distributed with this
7
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
*
9
* This file incorporates work covered by the following license notice:
10
*
11
* Licensed to the Apache Software Foundation (ASF) under one or more
12
* contributor license agreements. See the NOTICE file distributed
13
* with this work for additional information regarding copyright
14
* ownership. The ASF licenses this file to you under the Apache
15
* License, Version 2.0 (the "License"); you may not use this file
16
* except in compliance with the License. You may obtain a copy of
17
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
*/
19
20
#include <com/sun/star/sdbc/XResultSet.hpp>
21
#include <com/sun/star/ucb/XContentAccess.hpp>
22
#include <com/sun/star/ucb/CommandAbortedException.hpp>
23
#include <
comphelper/DirectoryHelper.hxx
>
24
#include <
comphelper/processfactory.hxx
>
25
#include <
comphelper/sequence.hxx
>
26
#include <
sal/log.hxx
>
27
#include <
unotools/localfilehelper.hxx
>
28
#include <rtl/ustring.hxx>
29
#include <
ucbhelper/content.hxx
>
30
#include <vector>
31
32
using namespace
::
osl
;
33
using namespace
::
com::sun::star::uno
;
34
using namespace
::
com::sun::star::ucb
;
35
36
namespace
utl
37
{
38
39
css::uno::Sequence < OUString >
LocalFileHelper::GetFolderContents
(
const
OUString& rFolder,
bool
bFolder )
40
{
41
std::vector< OUString > vFiles;
42
try
43
{
44
::ucbhelper::Content
aCnt(
45
rFolder, Reference< XCommandEnvironment >(),
46
comphelper::getProcessComponentContext
() );
47
Reference< css::sdbc::XResultSet > xResultSet;
48
css::uno::Sequence< OUString > aProps {
"Url"
};
49
50
try
51
{
52
::ucbhelper::ResultSetInclude
eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
53
xResultSet = aCnt.
createCursor
( aProps, eInclude );
54
}
55
catch
( css::ucb::CommandAbortedException& )
56
{
57
}
58
catch
(
Exception
& )
59
{
60
}
61
62
if
( xResultSet.is() )
63
{
64
Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
65
try
66
{
67
while
( xResultSet->next() )
68
vFiles.push_back( xContentAccess->queryContentIdentifierString() );
69
}
70
catch
( css::ucb::CommandAbortedException& )
71
{
72
}
73
catch
(
Exception
& )
74
{
75
}
76
}
77
}
78
catch
(
Exception
& )
79
{
80
}
81
82
return
comphelper::containerToSequence
(vFiles);
83
}
84
85
void
removeTree
(OUString
const
& url) {
86
const
bool
bError =
comphelper::DirectoryHelper::deleteDirRecursively
(url);
87
SAL_WARN_IF
(bError,
"desktop.app"
,
"error removing directory "
<< url);
88
}
89
90
}
91
92
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DirectoryHelper.hxx
comphelper::DirectoryHelper::deleteDirRecursively
static bool deleteDirRecursively(const OUString &rDirURL)
ucbhelper::Content
ucbhelper::Content::createCursor
css::uno::Reference< css::sdbc::XResultSet > createCursor(const css::uno::Sequence< OUString > &rPropertyNames, ResultSetInclude eMode=INCLUDE_FOLDERS_AND_DOCUMENTS)
utl::LocalFileHelper::GetFolderContents
static css::uno::Sequence< OUString > GetFolderContents(const OUString &rFolder, bool bFolder)
Definition:
localfilehelper.cxx:39
content.hxx
localfilehelper.hxx
log.hxx
SAL_WARN_IF
#define SAL_WARN_IF(condition, area, stream)
Sort::Exception
@ Exception
com::sun::star::ucb
com::sun::star::uno
comphelper::containerToSequence
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
comphelper::getProcessComponentContext
Reference< XComponentContext > getProcessComponentContext()
osl
ucbhelper::ResultSetInclude
ResultSetInclude
utl
utl::removeTree
void removeTree(OUString const &url)
recursively remove directory and all contents
Definition:
localfilehelper.cxx:85
processfactory.hxx
sequence.hxx
Generated on Sun Jul 30 2023 04:29:26 for LibreOffice Module unotools (master) by
1.9.3