/src/libreoffice/unotools/source/ucbhelper/localfilehelper.cxx
Line | Count | Source |
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 ::com::sun::star::uno; |
33 | | using namespace ::com::sun::star::ucb; |
34 | | |
35 | | namespace utl |
36 | | { |
37 | | |
38 | | css::uno::Sequence < OUString > LocalFileHelper::GetFolderContents( const OUString& rFolder, bool bFolder ) |
39 | 0 | { |
40 | 0 | std::vector< OUString > vFiles; |
41 | 0 | try |
42 | 0 | { |
43 | 0 | ::ucbhelper::Content aCnt( |
44 | 0 | rFolder, Reference< XCommandEnvironment >(), |
45 | 0 | comphelper::getProcessComponentContext() ); |
46 | 0 | Reference< css::sdbc::XResultSet > xResultSet; |
47 | 0 | css::uno::Sequence< OUString > aProps { u"Url"_ustr }; |
48 | |
|
49 | 0 | try |
50 | 0 | { |
51 | 0 | ::ucbhelper::ResultSetInclude eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY; |
52 | 0 | xResultSet = aCnt.createCursor( aProps, eInclude ); |
53 | 0 | } |
54 | 0 | catch( css::ucb::CommandAbortedException& ) |
55 | 0 | { |
56 | 0 | } |
57 | 0 | catch( Exception& ) |
58 | 0 | { |
59 | 0 | } |
60 | |
|
61 | 0 | if ( xResultSet.is() ) |
62 | 0 | { |
63 | 0 | Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY ); |
64 | 0 | try |
65 | 0 | { |
66 | 0 | while ( xResultSet->next() ) |
67 | 0 | vFiles.push_back( xContentAccess->queryContentIdentifierString() ); |
68 | 0 | } |
69 | 0 | catch( css::ucb::CommandAbortedException& ) |
70 | 0 | { |
71 | 0 | } |
72 | 0 | catch( Exception& ) |
73 | 0 | { |
74 | 0 | } |
75 | 0 | } |
76 | 0 | } |
77 | 0 | catch( Exception& ) |
78 | 0 | { |
79 | 0 | } |
80 | |
|
81 | 0 | return comphelper::containerToSequence(vFiles); |
82 | 0 | } |
83 | | |
84 | 0 | void removeTree(OUString const & url) { |
85 | 0 | const bool bError = comphelper::DirectoryHelper::deleteDirRecursively(url); |
86 | 0 | SAL_WARN_IF(bError, "desktop.app", "error removing directory " << url); |
87 | 0 | } |
88 | | |
89 | | } |
90 | | |
91 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |