1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: regview.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_registry.hxx"
36 #include "registry/registry.h"
37 #include <rtl/ustring.hxx>
38 #include <rtl/alloc.h>
39 #include <osl/process.h>
40 #include <osl/diagnose.h>
41 #include <osl/thread.h>
42 #include <osl/file.hxx>
47 #define SEPARATOR '\\'
50 using namespace ::rtl
;
51 using namespace ::osl
;
53 sal_Bool
isFileUrl(const OString
& fileName
)
55 if (fileName
.indexOf("file://") == 0 )
60 OUString
convertToFileUrl(const OString
& fileName
)
62 if ( isFileUrl(fileName
) )
64 return OStringToOUString(fileName
, osl_getThreadTextEncoding());
67 OUString uUrlFileName
;
68 OUString
uFileName(fileName
.getStr(), fileName
.getLength(), osl_getThreadTextEncoding());
69 if ( fileName
.indexOf('.') == 0 || fileName
.indexOf(SEPARATOR
) < 0 )
72 if (osl_getProcessWorkingDir(&uWorkingDir
.pData
) != osl_Process_E_None
)
76 if (FileBase::getAbsoluteFileURL(uWorkingDir
, uFileName
, uUrlFileName
)
83 if (FileBase::getFileURLFromSystemPath(uFileName
, uUrlFileName
)
94 #if (defined UNX) || (defined OS2)
95 int main( int argc
, char * argv
[] )
97 int _cdecl
main( int argc
, char * argv
[] )
101 RegKeyHandle hRootKey
, hKey
;
103 if (argc
< 2 || argc
> 3)
105 fprintf(stderr
, "using: regview registryfile [keyName]\n");
109 OUString
regName( convertToFileUrl(argv
[1]) );
110 if (reg_openRegistry(regName
.pData
, &hReg
, REG_READONLY
))
112 fprintf(stderr
, "open registry \"%s\" failed\n", argv
[1]);
116 if (!reg_openRootKey(hReg
, &hRootKey
))
120 OUString
keyName( OUString::createFromAscii(argv
[2]) );
121 if (!reg_openKey(hRootKey
, keyName
.pData
, &hKey
))
123 if (reg_dumpRegistry(hKey
))
125 fprintf(stderr
, "dumping registry \"%s\" failed\n", argv
[1]);
128 if (reg_closeKey(hKey
))
130 fprintf(stderr
, "closing key \"%s\" of registry \"%s\" failed\n",
135 fprintf(stderr
, "key \"%s\" not exists in registry \"%s\"\n",
140 if (reg_dumpRegistry(hRootKey
))
142 fprintf(stderr
, "dumping registry \"%s\" failed\n", argv
[1]);
146 if (reg_closeKey(hRootKey
))
148 fprintf(stderr
, "closing root key of registry \"%s\" failed\n", argv
[1]);
152 fprintf(stderr
, "open root key of registry \"%s\" failed\n", argv
[1]);
155 if (reg_closeRegistry(hReg
))
157 fprintf(stderr
, "closing registry \"%s\" failed\n", argv
[1]);