1*51134e9eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*51134e9eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*51134e9eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*51134e9eSAndrew Rist * distributed with this work for additional information
6*51134e9eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*51134e9eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*51134e9eSAndrew Rist * "License"); you may not use this file except in compliance
9*51134e9eSAndrew Rist * with the License. You may obtain a copy of the License at
10*51134e9eSAndrew Rist *
11*51134e9eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*51134e9eSAndrew Rist *
13*51134e9eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*51134e9eSAndrew Rist * software distributed under the License is distributed on an
15*51134e9eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*51134e9eSAndrew Rist * KIND, either express or implied. See the License for the
17*51134e9eSAndrew Rist * specific language governing permissions and limitations
18*51134e9eSAndrew Rist * under the License.
19*51134e9eSAndrew Rist *
20*51134e9eSAndrew Rist *************************************************************/
21*51134e9eSAndrew Rist
22*51134e9eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "fileurl.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "rtl/ustring.hxx"
27cdf0e10cSrcweir #include "osl/diagnose.h"
28cdf0e10cSrcweir #include "osl/file.hxx"
29cdf0e10cSrcweir #include "osl/process.h"
30cdf0e10cSrcweir #include "osl/thread.h"
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <string.h>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #ifdef SAL_UNX
35cdf0e10cSrcweir #define SEPARATOR '/'
36cdf0e10cSrcweir #else
37cdf0e10cSrcweir #define SEPARATOR '\\'
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir
40cdf0e10cSrcweir using rtl::OUString;
41cdf0e10cSrcweir using osl::FileBase;
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace registry
44cdf0e10cSrcweir {
45cdf0e10cSrcweir namespace tools
46cdf0e10cSrcweir {
47cdf0e10cSrcweir
convertToFileUrl(char const * filename,size_t length)48cdf0e10cSrcweir OUString convertToFileUrl(char const * filename, size_t length)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir OUString const uFileName(filename, length, osl_getThreadTextEncoding());
51cdf0e10cSrcweir if (strncmp(filename, "file://", 7) == 0)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir // already a FileUrl.
54cdf0e10cSrcweir return uFileName;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
57cdf0e10cSrcweir OUString uFileUrl;
58cdf0e10cSrcweir if (length > 0)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir if ((filename[0] == '.') || (filename[0] != SEPARATOR))
61cdf0e10cSrcweir {
62cdf0e10cSrcweir // relative path name.
63cdf0e10cSrcweir OUString uWorkingDir;
64cdf0e10cSrcweir if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir OSL_ASSERT(false);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uFileUrl) != FileBase::E_None)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir OSL_ASSERT(false);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir }
73cdf0e10cSrcweir else
74cdf0e10cSrcweir {
75cdf0e10cSrcweir // absolute path name.
76cdf0e10cSrcweir if (FileBase::getFileURLFromSystemPath(uFileName, uFileUrl) != FileBase::E_None)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir OSL_ASSERT(false);
79cdf0e10cSrcweir }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir }
82cdf0e10cSrcweir return uFileUrl;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir } // namespace tools
86cdf0e10cSrcweir } // namespace registry
87