>From 0ad28d8e2cd319c2857a207acdd1a9f43b52791c Mon Sep 17 00:00:00 2001
From: unknown <Amos@.(none)>
Date: Mon, 7 Jun 2010 10:52:19 +0300
Subject: [PATCH 5/8] download registry hive once.

---
 lib/Sys/VirtV2V/Converter/Windows.pm |  104 ++++++++++------------------------
 1 files changed, 31 insertions(+), 73 deletions(-)

diff --git a/lib/Sys/VirtV2V/Converter/Windows.pm b/lib/Sys/VirtV2V/Converter/Windows.pm
index 94b7964..dfc52d7 100644
--- a/lib/Sys/VirtV2V/Converter/Windows.pm
+++ b/lib/Sys/VirtV2V/Converter/Windows.pm
@@ -190,26 +190,24 @@ sub _preconvert
 
     _upload_viostor ($g, $tmpdir, $desc, $devices, $config,
                      $transfer_mount);
-    _add_viostor_to_registry ($g, $tmpdir, $desc, $devices, $config,
-                              $transfer_mount);
     _upload_service ($g, $tmpdir, $desc, $devices, $config,
                      $transfer_mount);
-    _add_service_to_registry ($g, $tmpdir, $desc, $devices, $config,
-                              $transfer_mount);
-    _disable_vmware_tools ($g, $tmpdir, $desc, $devices, $config,
-                              $transfer_mount);
+    
+    _update_system_registry ($g, $tmpdir, $desc, $devices, $config,
+                             $transfer_mount);                 
+                             
 }
 
-# See http://rwmj.wordpress.com/2010/04/30/tip-install-a-device-driver-in-a-windows-vm/
-sub _add_viostor_to_registry
+sub _update_system_registry
 {
-    my $g = shift;
+
+       my $g = shift;
     my $tmpdir = shift;
     my $desc = shift;
     my $devices = shift;
     my $config = shift;
     my $transfer_mount = shift;
-
+     
     # Locate and download the system registry.
     my $system_filename;
     eval {
@@ -223,9 +221,28 @@ sub _add_viostor_to_registry
     }
 
     # Open the registry hive.
-    my $h = Win::Hivex->open ($tmpdir . "/system", write => 1)
+    my $system_h = Win::Hivex->open ($tmpdir . "/system", write => 1)
         or die "open system hive: $!";
 
+                                           
+    _add_viostor_to_registry ($system_h, $desc);
+    _add_service_to_registry ($system_h, $desc);
+    _disable_vmware_tools ($system_h, $desc);
+
+    $system_h->commit (undef);
+    undef $system_h;
+
+    # Upload the new registry.
+    $g->upload ($tmpdir . "/system", $system_filename);     
+
+}
+
+# See http://rwmj.wordpress.com/2010/04/30/tip-install-a-device-driver-in-a-windows-vm/
+sub _add_viostor_to_registry
+{
+    my $h = shift;
+    my $desc = shift;
+
     # Make the changes.
     my $regedits = '
 ; Edits to be made to a Windows guest to have
@@ -293,39 +310,13 @@ sub _add_viostor_to_registry
     };
 
     reg_import ($io, \&_map);
-
-    $h->commit (undef);
-    undef $h;
-
-    # Upload the new registry.
-    $g->upload ($tmpdir . "/system", $system_filename);
 }
 
 # See http://rwmj.wordpress.com/2010/04/29/tip-install-a-service-in-a-windows-vm/
 sub _add_service_to_registry
 {
-    my $g = shift;
-    my $tmpdir = shift;
+    my $h = shift;
     my $desc = shift;
-    my $devices = shift;
-    my $config = shift;
-    my $transfer_mount = shift;
-
-    # Locate and download the system registry.
-    my $system_filename;
-    eval {
-        $system_filename = "/windows/system32/config/system";
-        $system_filename = $g->case_sensitive_path ($system_filename);
-        $g->download ($system_filename, $tmpdir . "/system");
-    };
-    if ($@) {
-        die (user_message (__x"Could not download the SYSTEM registry from this Windows guest.  The exact error message was: {errmsg}",
-                           errmsg => $@));
-    }
-
-    # Open the registry hive.
-    my $h = Win::Hivex->open ($tmpdir . "/system", write => 1)
-        or die "open system hive: $!";
 
     # Make the changes.
     my $regedits = '
@@ -353,43 +344,15 @@ sub _add_service_to_registry
 
     reg_import ($io, \&_map);
 
-    $h->commit (undef);
-    undef $h;
-
-    # Upload the new registry.
-    $g->upload ($tmpdir . "/system", $system_filename);
 }
 
 sub _disable_vmware_tools
 {
-    my $g = shift;
-    my $tmpdir = shift;
+    my $h = shift;
     my $desc = shift;
-    my $devices = shift;
-    my $config = shift;
-    my $transfer_mount = shift;
-
-    # Locate and download the system registry.
-    my $system_filename;
-    eval {
-        $system_filename = "/windows/system32/config/system";
-        $system_filename = $g->case_sensitive_path ($system_filename);
-        $g->download ($system_filename, $tmpdir . "/system");
-    };
-    if ($@) {
-        die (user_message (__x"Could not download the SYSTEM registry from this Windows guest.  The exact error message was: {errmsg}",
-                           errmsg => $@));
-    }
-
-    # Open the registry hive.
-    my $h = Win::Hivex->open ($tmpdir . "/system", write => 1)
-        or die "open system hive: $!";
 
     # Make the changes.
-    my $regedits = '
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Parport]
-"Start"=dword:00000004
-    
+    my $regedits = '   
 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\vmci]
 "Start"=dword:00000004
 
@@ -427,11 +390,6 @@ sub _disable_vmware_tools
 
     reg_import ($io, \&_map);
 
-    $h->commit (undef);
-    undef $h;
-
-    # Upload the new registry.
-    $g->upload ($tmpdir . "/system", $system_filename);
 }
 
 sub _upload_viostor
-- 
1.6.1.9.g97c34

