update dev300-m58
[ooovba.git] / registry / tools / regview.cxx
blob55a9c186e34c9c4d164f096cb0bc9f5272cebfb4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: regview.cxx,v $
10 * $Revision: 1.6 $
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"
34 #include <stdio.h>
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>
44 #ifdef SAL_UNX
45 #define SEPARATOR '/'
46 #else
47 #define SEPARATOR '\\'
48 #endif
50 using namespace ::rtl;
51 using namespace ::osl;
53 sal_Bool isFileUrl(const OString& fileName)
55 if (fileName.indexOf("file://") == 0 )
56 return sal_True;
57 return sal_False;
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 )
71 OUString uWorkingDir;
72 if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
74 OSL_ASSERT(false);
76 if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
77 != FileBase::E_None)
79 OSL_ASSERT(false);
81 } else
83 if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
84 != FileBase::E_None)
86 OSL_ASSERT(false);
90 return uUrlFileName;
94 #if (defined UNX) || (defined OS2)
95 int main( int argc, char * argv[] )
96 #else
97 int _cdecl main( int argc, char * argv[] )
98 #endif
100 RegHandle hReg;
101 RegKeyHandle hRootKey, hKey;
103 if (argc < 2 || argc > 3)
105 fprintf(stderr, "using: regview registryfile [keyName]\n");
106 exit(1);
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]);
113 exit(1);
116 if (!reg_openRootKey(hReg, &hRootKey))
118 if (argc == 3)
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",
131 argv[2], argv[1]);
133 } else
135 fprintf(stderr, "key \"%s\" not exists in registry \"%s\"\n",
136 argv[2], argv[1]);
138 } else
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]);
150 } else
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]);
158 exit(1);
161 return(0);