Author: remi
Date: 2008-11-30 15:03:34 +0100 (Sun, 30 Nov 2008)
New Revision: 2936

Modified:
   software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/DongleHIDCheck.pas
   software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/Tuxup.pas
Log:
* updated wrappers

Modified: 
software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/DongleHIDCheck.pas
===================================================================
--- software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/DongleHIDCheck.pas  
2008-11-30 13:47:34 UTC (rev 2935)
+++ software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/DongleHIDCheck.pas  
2008-11-30 14:03:34 UTC (rev 2936)
@@ -4,8 +4,11 @@
 
 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, ShellApi;
+  Dialogs, StdCtrls, ShellApi, Registry;
 
+const
+  TUXDROID_REGISTRY_PATH = 'SOFTWARE\Tuxdroid\TuxdroidSetup';
+
 type
   TDongleHIDCheck = class(TObject)
   public
@@ -16,6 +19,9 @@
 
 implementation
 
+var
+  tuxdroidPath : string;
+
 function ShellExecute_AndWait(Operation, FileName, Parameter, Directory: 
string;
   Show: Word; bWait: Boolean): Longint;
 var
@@ -46,6 +52,28 @@
   if not bOK then Result := -1;
 end;
 
+{**
+ * Get the Tuxdroid installation path.
+ *}
+function getTuxdroidPath : string;
+begin
+  result := '';
+  with TRegistry.Create do
+    try
+      RootKey := HKEY_LOCAL_MACHINE;
+
+      // From Tuxdroid setup
+      if OpenKey(TUXDROID_REGISTRY_PATH, False) then
+      begin
+        // Get tuxdroid installation path
+        result := ReadString('Install_Dir');
+        CloseKey;
+      end;
+    finally
+      Free;
+    end;
+end;
+
 constructor TDongleHIDCheck.create(AOwner : TComponent);
 begin
   isWorking := false;
@@ -53,16 +81,14 @@
 
 function TDongleHIDCheck.check : boolean;
 var
-  filePath, cmd : string;
+  cmd : string;
   ret : integer;
 begin
-  filePath := extractfilepath(application.ExeName);
-
   cmd := '';
 
   isWorking := true;
   ret := ShellExecute_AndWait( 'open',
-                          PChar(filePath + 'dongle_hid_check.exe'),
+                          PChar(tuxdroidPath + '\bin\dongle_hid_check.exe'),
                           PChar(cmd),
                           PChar(''),
                           SW_HIDE,
@@ -78,4 +104,7 @@
   result := true;
 end;
 
+initialization
+  tuxdroidPath := getTuxdroidPath;
+
 end.

Modified: software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/Tuxup.pas
===================================================================
--- software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/Tuxup.pas   
2008-11-30 13:47:34 UTC (rev 2935)
+++ software_suite_v2/tuxware/tuxdroidflasher/trunk/flasher/Tuxup.pas   
2008-11-30 14:03:34 UTC (rev 2936)
@@ -4,9 +4,10 @@
 
 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, ShellApi;
+  Dialogs, StdCtrls, ShellApi, Registry;
 
 const
+  TUXDROID_REGISTRY_PATH = 'SOFTWARE\Tuxdroid\TuxdroidSetup';
   // Error codes enumeration.
   E_TUXUP_NOERROR                 = 0;
   E_TUXUP_CMDNOTFOUND             = 1;
@@ -33,6 +34,9 @@
 
 implementation
 
+var
+  tuxdroidPath : string;
+
 function ShellExecute_AndWait(Operation, FileName, Parameter, Directory: 
string;
   Show: Word; bWait: Boolean): Longint;
 var
@@ -63,6 +67,28 @@
   if not bOK then Result := -1;
 end;
 
+{**
+ * Get the Tuxdroid installation path.
+ *}
+function getTuxdroidPath : string;
+begin
+  result := '';
+  with TRegistry.Create do
+    try
+      RootKey := HKEY_LOCAL_MACHINE;
+
+      // From Tuxdroid setup
+      if OpenKey(TUXDROID_REGISTRY_PATH, False) then
+      begin
+        // Get tuxdroid installation path
+        result := ReadString('Install_Dir');
+        CloseKey;
+      end;
+    finally
+      Free;
+    end;
+end;
+
 constructor TTuxup.create(AOwner : TComponent);
 begin
   isWorking := false;
@@ -70,15 +96,16 @@
 
 function TTuxup.flash(firmware : string) : integer;
 var
-  filePath, cmd : string;
+  cmd : string;
   ret : integer;
+  Buffer: Array[0..MAX_PATH] of char;
 begin
   // Stop the server
   try
-    if fileexists('C:\tuxdroid\bin\tuxhttpserver_stop.exe') then
+    if fileexists(tuxdroidPath + '\bin\tuxhttpserver_stop.exe') then
     begin
       ShellExecute_AndWait( 'open',
-        PChar('C:\tuxdroid\bin\tuxhttpserver_stop.exe'),
+        PChar(tuxdroidPath + '\bin\tuxhttpserver_stop.exe'),
         PChar(''),
         PChar(''),
         SW_HIDE,
@@ -88,16 +115,14 @@
   end;
   sleep(500);
 
-  // Flash the firmware
-  filePath := extractfilepath(application.ExeName);
-
   firmware := StringReplace(firmware, '\', '/',
                           [rfReplaceAll, rfIgnoreCase]);
+  GetShortPathName(PChar(firmware), @Buffer, SizeOf(Buffer));
 
-  cmd := format('"%s"', [firmware]);
+  cmd := format('"%s"', [Buffer]);
   isWorking := true;
   ret := ShellExecute_AndWait( 'open',
-                          PChar(filePath + 'tuxup.exe'),
+                          PChar(tuxdroidPath + '\bin\tuxup.exe'),
                           PChar(cmd),
                           PChar(''),
                           SW_HIDE,
@@ -106,10 +131,10 @@
 
   // Start the server
   try
-    if fileexists('C:\tuxdroid\bin\tuxhttpserver_start.exe') then
+    if fileexists(tuxdroidPath + '\bin\tuxhttpserver_start.exe') then
     begin
       ShellExecute_AndWait( 'open',
-        PChar('C:\tuxdroid\bin\tuxhttpserver_start.exe'),
+        PChar(tuxdroidPath + '\bin\tuxhttpserver_start.exe'),
         PChar(''),
         PChar(''),
         SW_HIDE,
@@ -123,24 +148,24 @@
 
 function TTuxup.flashEx(firmware : string) : integer;
 var
-  filePath, cmd : string;
+  cmd : string;
   ret : integer;
   count : integer;
+  Buffer: Array[0..MAX_PATH] of char;
 begin
   // Flash the firmware
-  filePath := extractfilepath(application.ExeName);
-
   firmware := StringReplace(firmware, '\', '/',
                           [rfReplaceAll, rfIgnoreCase]);
+  GetShortPathName(PChar(firmware), @Buffer, SizeOf(Buffer));
 
-  cmd := format('"%s"', [firmware]);
+  cmd := format('"%s"', [Buffer]);
   isWorking := true;
   count := 0;
 
   while true do
   begin
     ret := ShellExecute_AndWait( 'open',
-                          PChar(filePath + 'tuxup.exe'),
+                          PChar(tuxdroidPath + '\bin\tuxup.exe'),
                           PChar(cmd),
                           PChar(''),
                           SW_HIDE,
@@ -172,10 +197,10 @@
 procedure TTuxup.stopServer;
 begin
   try
-    if fileexists('C:\tuxdroid\bin\tuxhttpserver_stop.exe') then
+    if fileexists(tuxdroidPath + '\bin\tuxhttpserver_stop.exe') then
     begin
       ShellExecute_AndWait( 'open',
-        PChar('C:\tuxdroid\bin\tuxhttpserver_stop.exe'),
+        PChar(tuxdroidPath + '\bin\tuxhttpserver_stop.exe'),
         PChar(''),
         PChar(''),
         SW_HIDE,
@@ -189,10 +214,10 @@
 procedure TTuxup.startServer;
 begin
   try
-    if fileexists('C:\tuxdroid\bin\tuxhttpserver_start.exe') then
+    if fileexists(tuxdroidPath + '\bin\tuxhttpserver_start.exe') then
     begin
       ShellExecute_AndWait( 'open',
-        PChar('C:\tuxdroid\bin\tuxhttpserver_start.exe'),
+        PChar(tuxdroidPath + '\bin\tuxhttpserver_start.exe'),
         PChar(''),
         PChar(''),
         SW_HIDE,
@@ -202,4 +227,7 @@
   end;
 end;
 
+initialization
+  tuxdroidPath := getTuxdroidPath;
+
 end.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to