Log Message:
-----------
Store details of discovered local servers in the registry for potential modification.
Don't barf an error if HKLM\Software\PostgreSQL\Servers doesn't exist.

Modified Files:
--------------
    pgadmin3/src/ui:
        frmMain.cpp (r1.98 -> r1.99)

Index: frmMain.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/frmMain.cpp,v
retrieving revision 1.98
retrieving revision 1.99
diff -Lsrc/ui/frmMain.cpp -Lsrc/ui/frmMain.cpp -u -w -r1.98 -r1.99
--- src/ui/frmMain.cpp
+++ src/ui/frmMain.cpp
@@ -754,15 +754,19 @@
     wxLogInfo(wxT("Storing listed servers for later..."));
 
     // Store the currently listed servers for later retrieval.
-
-    // Write the individual servers
-    // Iterate through all the child nodes of the Servers node
     wxCookieType cookie;
     wxString key;
     pgObject *data;
     pgServer *server;
     int numServers = 0;
 
+       // Get the hostname for later...
+       char buf[255];
+       gethostname(buf, 255); 
+    wxString hostname = wxString(buf, wxConvUTF8);
+
+    // Write the individual servers
+    // Iterate through all the child nodes of the Servers node
     wxTreeItemId item = browser->GetFirstChild(servers, cookie);
     while (item) {
 
@@ -781,6 +785,7 @@
                            key.Printf(wxT("Servers/Server%d"), numServers);
                        settings->Write(key, server->GetName());
        
+                               // Comment
                        key.Printf(wxT("Servers/Description%d"), numServers);
                    settings->Write(key, server->GetDescription());
 
@@ -808,17 +813,47 @@
                                key.Printf(wxT("Servers/LastSchema%d"), numServers);
                                settings->Write(key, server->GetLastSchema());
                    
+                               // SSL
                                key.Printf(wxT("Servers/SSL%d"), numServers);
                    settings->Write(key, server->GetSSL());
 
                        } else {
 
-                               // This is a discovered server, so just store the 
lastSchema/lastDatabase
-                               key.Printf(wxT("Servers/LastDatabase-%s"), 
server->GetServiceID());
+                               // This is a discovered server...
+                               // Hostname
+                               key.Printf(wxT("Servers/Server-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, server->GetName());
+
+                               // Comment
+                               key.Printf(wxT("Servers/Description-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, server->GetDescription());
+
+                               // Port
+                               key.Printf(wxT("Servers/Port-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, server->GetPort());
+
+                               // Trusted
+                               key.Printf(wxT("Servers/Trusted-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, BoolToStr(server->GetTrusted()));
+
+                               // Database
+                               key.Printf(wxT("Servers/Database-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, server->GetDatabaseName());
+
+                               // Username
+                               key.Printf(wxT("Servers/Username-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, server->GetUsername());
+
+                               // SSL
+                               key.Printf(wxT("Servers/SSL-%s-%s"), hostname, 
server->GetServiceID());
+                       settings->Write(key, server->GetSSL());
+
+                               // Last Database
+                               key.Printf(wxT("Servers/LastDatabase-%s-%s"), 
hostname, server->GetServiceID());
                                settings->Write(key, server->GetLastDatabase());
        
-                               // last Schema
-                               key.Printf(wxT("Servers/LastSchema-%s"), 
server->GetServiceID());
+                               // Last Schema
+                               key.Printf(wxT("Servers/LastSchema-%s-%s"), hostname, 
server->GetServiceID());
                                settings->Write(key, server->GetLastSchema());
                        }
                }
@@ -843,6 +878,11 @@
     wxString key, servername, description, database, username, lastDatabase, 
lastSchema, trusted;
     pgServer *server;
 
+       // Get the hostname for later...
+       char buf[255];
+       gethostname(buf, 255); 
+    wxString hostname = wxString(buf, wxConvUTF8);
+
     for (loop = 1; loop <= numServers; ++loop) {
         
         // Server
@@ -897,7 +937,10 @@
        // of the Win32 PostgreSQL installer.
        wxRegKey *pgKey = new 
wxRegKey(wxT("HKEY_LOCAL_MACHINE\\Software\\PostgreSQL\\Services"));
 
-       wxString svcName;
+       if (pgKey->Exists())
+       {
+
+               wxString svcName, temp;
        long cookie = 0;
        bool flag = false;
 
@@ -908,22 +951,48 @@
                
key.Printf(wxT("HKEY_LOCAL_MACHINE\\Software\\PostgreSQL\\Services\\%s"), svcName);
                wxRegKey *svcKey = new wxRegKey(key);
 
+                       // Server
+                       key.Printf(wxT("Servers/Server-%s-%s"), hostname, svcName);
+                       settings->Read(key, &servername, wxT("127.0.0.1"));
+
         // Comment
-               svcKey->QueryValue(wxT("Display Name"), description);
+                       svcKey->QueryValue(wxT("Display Name"), temp);
+                       key.Printf(wxT("Servers/Description-%s-%s"), hostname, 
svcName);
+                       settings->Read(key, &description, temp);
+
+                       // Database
+                       key.Printf(wxT("Servers/Database-%s-%s"), hostname, svcName);
+                       settings->Read(key, &database, wxT("template1"));
 
         // Username
-               svcKey->QueryValue(wxT("Database Superuser"), username);
+                       svcKey->QueryValue(wxT("Database Superuser"), temp);
+                       key.Printf(wxT("Servers/Username-%s-%s"), hostname, svcName);
+                       settings->Read(key, &username, temp);
+
+                       // Port
+                       key.Printf(wxT("Servers/Port-%s-%s"), hostname, svcName);
+                       settings->Read(key, &port, 5432);
+
+                       // Trusted
+                       key.Printf(wxT("Servers/Trusted-%s-%s"), hostname, svcName);
+                       settings->Read(key, &trusted, wxT("false"));
+
+#ifdef SSL
+                       // SSL
+                       key.Printf(wxT("Servers/SSL-%s-%s"), hostname, svcName);
+                       settings->Read(key, &ssl, 0);
+#endif //SSL
 
         // last Database
-        key.Printf(wxT("Servers/LastDatabase-%s"), svcName);
+                       key.Printf(wxT("Servers/LastDatabase-%s-%s"), hostname, 
svcName);
         settings->Read(key, &lastDatabase, wxT(""));
 
         // last Schema
-        key.Printf(wxT("Servers/LastSchema-%s"), svcName);
+                       key.Printf(wxT("Servers/LastSchema-%s-%s"), hostname, svcName);
         settings->Read(key, &lastSchema, wxT(""));
 
         // Add the Server node
-        server = new pgServer(wxT("127.0.0.1"), description, wxT("template1"), 
username, 5432, false, false);
+                       server = new pgServer(servername, description, database, 
username, port, StrToBool(trusted), ssl);
         server->iSetLastDatabase(lastDatabase);
         server->iSetLastSchema(lastSchema);
                server->iSetDiscovered(true);
@@ -933,6 +1002,7 @@
                // Get the next one...
                flag = pgKey->GetNextKey(svcName, cookie);
        }
+       }
 
 
 #endif //WIN32
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to