Page Breaks: IsLeaveWindow() is unreliable, we do not need it here.
[LibreOffice.git] / registry / tools / regmerge.cxx
blob8aac913ea01d231b4692bd3c0e78f04143d2a18a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "registry/registry.hxx"
31 #include "fileurl.hxx"
32 #include "options.hxx"
34 #include "rtl/ustring.hxx"
35 #include "osl/diagnose.h"
37 #include <stdio.h>
38 #include <string.h>
40 using namespace rtl;
41 using namespace registry::tools;
43 class Options_Impl : public Options
45 bool m_bVerbose;
47 public:
48 explicit Options_Impl (char const * program)
49 : Options(program), m_bVerbose(false)
51 bool isVerbose() const { return m_bVerbose; }
53 protected:
54 virtual void printUsage_Impl() const;
55 virtual bool initOptions_Impl(std::vector< std::string > & rArgs);
58 void Options_Impl::printUsage_Impl() const
60 fprintf(stderr, "using: regmerge [-v|--verbose] mergefile mergeKeyName regfile_1 ... regfile_n\n");
61 fprintf(stderr, " regmerge @regcmds\nOptions:\n");
62 fprintf(stderr, " -v, --verbose : verbose output on stdout.\n");
63 fprintf(stderr, " mergefile : specifies the merged registry file. If this file doesn't exists,\n");
64 fprintf(stderr, " it is created.\n");
65 fprintf(stderr, " mergeKeyName : specifies the merge key, everything is merged under this key.\n");
66 fprintf(stderr, " If this key doesn't exists, it is created.\n");
67 fprintf(stderr, " regfile_1..n : specifies one or more registry files which are merged.\n");
70 bool Options_Impl::initOptions_Impl (std::vector< std::string > & rArgs)
72 std::vector< std::string >::iterator first = rArgs.begin(), last = rArgs.end();
73 if ((first != last) && ((*first)[0] == '-'))
75 std::string option(*first);
76 if ((option.compare("-v") == 0) || (option.compare("--verbose") == 0))
78 m_bVerbose = true;
80 else if ((option.compare("-h") == 0) || (option.compare("-?") == 0))
82 return printUsage();
84 else
86 return badOption("unknown", option.c_str());
88 (void) rArgs.erase(first);
90 return true;
93 #if (defined UNX)
94 int main( int argc, char * argv[] )
95 #else
96 int __cdecl main( int argc, char * argv[] )
97 #endif
99 Options_Impl options(argv[0]);
101 std::vector< std::string > args;
102 for (int i = 1; i < argc; i++)
104 if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
106 options.printUsage();
107 return (1);
110 if (!options.initOptions(args))
112 return (1);
114 if (args.size() < 3)
116 options.printUsage();
117 return (1);
120 Registry reg;
121 OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
122 if (reg.open(regName, REG_READWRITE) != REG_NO_ERROR)
124 if (reg.create(regName) != REG_NO_ERROR)
126 if (options.isVerbose())
127 fprintf(stderr, "open registry \"%s\" failed\n", args[0].c_str());
128 return (-1);
132 RegistryKey rootKey;
133 if (reg.openRootKey(rootKey) != REG_NO_ERROR)
135 if (options.isVerbose())
136 fprintf(stderr, "open root key of registry \"%s\" failed\n", args[0].c_str());
137 return (-4);
140 OUString mergeKeyName( OUString::createFromAscii(args[1].c_str()) );
141 for (size_t i = 2; i < args.size(); i++)
143 OUString targetRegName( convertToFileUrl(args[i].c_str(), args[i].size()) );
144 RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, sal_False, options.isVerbose());
145 if (_ret != REG_NO_ERROR)
147 if (_ret == REG_MERGE_CONFLICT)
149 if (options.isVerbose())
150 fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
151 args[i].c_str(), args[1].c_str(), args[0].c_str());
153 else
155 if (options.isVerbose())
156 fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
157 args[i].c_str(), args[1].c_str(), args[0].c_str());
158 return (-2);
161 else
163 if (options.isVerbose())
164 fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
165 args[i].c_str(), args[1].c_str(), args[0].c_str());
169 rootKey.releaseKey();
170 if (reg.close() != REG_NO_ERROR)
172 if (options.isVerbose())
173 fprintf(stderr, "closing registry \"%s\" failed\n", args[0].c_str());
174 return (-5);
177 return(0);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */