Code

remove desktop-affine.cpp
[inkscape.git] / src / registrytool.cpp
index 6747a0dd8445e2bae6253ffea24903c6afd50737..8bc9cbebf6e4b3520ab014c2e8ba1b8b88b35e93 100644 (file)
@@ -8,7 +8,7 @@
  * Authors:
  *   Bob Jamison
  *
- * Copyright (C) 2005 Bob Jamison
+ * Copyright (C) 2005-2008 Bob Jamison
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -33,9 +33,9 @@
 
 typedef struct
 {
-    HKEY key;
-    int  strlen;
-    char *str;
+    HKEY       key;
+    int        strlen;
+    const char *str;
 } KeyTableEntry;
 
 
@@ -50,11 +50,15 @@ KeyTableEntry keyTable[] =
     { NULL,                 0, NULL                    }
 };
 
-bool RegistryTool::setStringValue(const std::string &keyNameArg,
-                                  const std::string &valueName,
-                                  const std::string &value)
+
+/**
+ * Set the string value of a key/name registry entry
+ */ 
+bool RegistryTool::setStringValue(const Glib::ustring &keyNameArg,
+                                  const Glib::ustring &valueName,
+                                  const Glib::ustring &value)
 {
-    std::string keyName = keyNameArg;
+    Glib::ustring keyName = keyNameArg;
 
     HKEY rootKey = HKEY_LOCAL_MACHINE; //default root
     //Trim out the root key if necessary
@@ -74,7 +78,7 @@ bool RegistryTool::setStringValue(const std::string &keyNameArg,
                        0, NULL, REG_OPTION_NON_VOLATILE,
                        KEY_WRITE, NULL, &key, NULL))
        {
-       printf("RegistryTool: Could not create the registry key '%s'\n", keyName.c_str());
+       fprintf(stderr, "RegistryTool: Could not create the registry key '%s'\n", keyName.c_str());
        return false;
        }
 
@@ -82,7 +86,7 @@ bool RegistryTool::setStringValue(const std::string &keyNameArg,
     if (RegSetValueEx(key, valueName.c_str(),
           0,  REG_SZ, (LPBYTE) value.c_str(), (DWORD) value.size()))
        {
-       printf("RegistryTool: Could not set the value '%s'\n", value.c_str());
+       fprintf(stderr, "RegistryTool: Could not set the value '%s'\n", value.c_str());
        RegCloseKey(key);
        return false;
        }
@@ -93,15 +97,20 @@ bool RegistryTool::setStringValue(const std::string &keyNameArg,
     return true;
 }
 
-bool RegistryTool::getExeInfo(std::string &fullPath,
-                              std::string &path,
-                              std::string &exeName)
+
+
+/**
+ * Get the full path, directory, and base file name of this running executable
+ */ 
+bool RegistryTool::getExeInfo(Glib::ustring &fullPath,
+                              Glib::ustring &path,
+                              Glib::ustring &exeName)
 {
 
     char buf[MAX_PATH+1];
     if (!GetModuleFileName(NULL, buf, MAX_PATH))
         {
-        printf("Could not fetch executable file name\n");
+        fprintf(stderr, "Could not fetch executable file name\n");
         return false;
         }
     else
@@ -112,7 +121,7 @@ bool RegistryTool::getExeInfo(std::string &fullPath,
     fullPath = buf;
     path     = "";
     exeName  = "";
-    std::string::size_type pos = fullPath.rfind('\\');
+    Glib::ustring::size_type pos = fullPath.rfind('\\');
     if (pos != fullPath.npos)
         {
         path = fullPath.substr(0, pos);
@@ -123,11 +132,16 @@ bool RegistryTool::getExeInfo(std::string &fullPath,
 }
 
 
+
+/**
+ * Append our subdirectories to the Application Path for this
+ * application
+ */  
 bool RegistryTool::setPathInfo()
 {
-    std::string fullPath;
-    std::string path;
-    std::string exeName;
+    Glib::ustring fullPath;
+    Glib::ustring path;
+    Glib::ustring exeName;
 
     if (!getExeInfo(fullPath, path, exeName))
         return false;
@@ -135,18 +149,18 @@ bool RegistryTool::setPathInfo()
     //printf("full:'%s' path:'%s' exe:'%s'\n",
     //    fullPath.c_str(), path.c_str(), exeName.c_str());
 
-    std::string keyName =
+    Glib::ustring keyName =
     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
     keyName.append(exeName);
 
-    std::string valueName = "";
-    std::string value     = fullPath;
+    Glib::ustring valueName = "";
+    Glib::ustring value     = fullPath;
 
     if (!setStringValue(keyName, valueName, value))
         return false;
 
     //add our subdirectories
-    std::string appPath = path;
+    Glib::ustring appPath = path;
     appPath.append("\\python;");
     appPath.append(path);
     appPath.append("\\perl");
@@ -162,13 +176,22 @@ bool RegistryTool::setPathInfo()
 
 #ifdef TESTREG
 
+
+/**
+ * Compile this file with
+ *      g++ -DTESTREG registrytool.cpp -o registrytool
+ *  to run these tests.
+ */
+    
 void testReg()
 {
     RegistryTool rt;
     char *key =
     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\inkscape.exe";
-    char *name  = "";
-    char *value = "c:\\inkscape\\inkscape.exe";
+    char const *name  = "";
+    char const *value = "c:\\inkscape\\inkscape.exe";
     if (!rt.setStringValue(key, name, value))
         {
         printf("Test failed\n");