Revision
99
Author
emsmith
Date
2007-01-05 10:18:29 -0800 (Fri, 05 Jan 2007)

Log Message

Finished OS refactor, added run command

Modified Paths

Diff

Modified: trunk/lib/os.class.php (98 => 99)


--- trunk/lib/os.class.php	2007-01-05 17:54:24 UTC (rev 98)
+++ trunk/lib/os.class.php	2007-01-05 18:18:29 UTC (rev 99)
@@ -28,102 +28,12 @@
 class CC_Os
 {
 	/**
-	 * @const LINUX OS
-	 */
-	const LINUX = 1;
-
-	/**
-	 * @const UNIX OS
-	 */
-	const UNIX = 2;
-
-	/**
-	 * @const WIN32 OS
-	 */
-	const WIN32 = 3;
-
-	/**
-	 * @const WINNT OS
-	 */
-	const WINNT = 4;
-
-	/**
-	 * @const MAC OS
-	 */
-	const MAC = 5;
-
-	/**
-	 * @const GNOME Desktop
-	 */
-	const GNOME = 6;
-
-	/**
-	 * @const KDE Desktop
-	 */
-	const KDE = 7;
-
-	/**
-	 * @const unknown Desktop/OS
-	 */
-	const UNKNOWN = 8;
-
-	/**
 	 * singleton instance for this class
 	 * @var $singleton instanceof Characters
 	 */
 	static protected $singleton;
 
 	/**
-	 * protected function __construct
-	 *
-	 * Uses PHP_OS to get a "general" OS name and tries to figure out the
-	 * current desktop system
-	 *
-	 * @return void
-	 */
-	protected function __construct()
-	{
-		if (stristr(PHP_OS, 'winnt'))
-		{
-			$this->os = self::WINNT;
-		}
-		elseif (stristr(PHP_OS, 'win32'))
-		{
-			$this->os = self::WIN32;
-		}
-		elseif (stristr(PHP_OS, 'darwin') || stristr(PHP_OS, 'mac'))
-		{
-			$this->os = self::MAC;
-		}
-		elseif (stristr(PHP_OS, 'linux'))
-		{
-			$this->os = self::LINUX;
-		}
-		elseif (stristr(PHP_OS, 'freebsd') || stristr(PHP_OS, 'aix') || stristr(PHP_OS, 'unix'))
-		{
-			$this->os = self::UNIX;
-		}
-		else
-		{
-			$this->os = self::UNKNOWN;
-		}
-		if ((isset($_ENV['KDE_FULL_SESSION']) && $_ENV['KDE_FULL_SESSION'] == 'true') ||
-			(isset($_ENV['KDE_MULTIHEAD']) && $_ENV['KDE_MULTIHEAD'] == 'true'))
-		{
-			$this->desktop = self::KDE;
-		}
-		elseif (isset($_ENV['GNOME_DESKTOP_SESSION_ID']) || isset($_ENV['GNOME_KEYRING_SOCKET']))
-		{
-			$this->desktop = self::GNOME;
-		}
-		else
-		{
-			$this->desktop = self::UNKNOWN;
-		}
-		return;
-	}
-
-	/**
 	 * public function get_temp
 	 *
 	 * finds temp directory using best guesses per OS
@@ -282,6 +192,29 @@
 		}
 	}
 
+	/**
+	 * public function run
+	 *
+	 * replacement for exec, uses com on windows
+	 *
+	 * @param string $cmd command to send
+	 * @return bool
+	 */
+	public function run($cmd)
+	{
+		echo $cmd;
+		if (stristr(PHP_OS, 'win'))
+		{
+			$shell = new COM('WScript.Shell');
+			$return = $shell->Run($cmd, 0, false);
+			unset ($shell);
+			return (bool) $return;
+		}
+		else
+		{
+			return exec($cmd);
+		}
+	}
 
 	/**
 	 * public function launch
@@ -294,47 +227,40 @@
 	 */
 	public function launch($file)
 	{
-		if ($this->os == self::LINUX || $this->os == self::UNIX)
+		if (stristr(PHP_OS, 'winnt'))
 		{
+			$cmd = 'cmd /c start "" "' . $file . '"';
+		}
+		elseif (stristr(PHP_OS, 'win32'))
+		{
+			$cmd = 'command /c start "" "' . $file . '"';
+		}
+		elseif (stristr(PHP_OS, 'darwin') || stristr(PHP_OS, 'mac'))
+		{
+			$cmd = 'open "' . $file . '"';
+		}
+		else
+		{
 			// try to use desktop launch standard
 			if (isset($_ENV['DESKTOP_LAUNCH']))
 			{
-				$file = $_ENV['DESKTOP_LAUNCH'] . '"' . $file . '"';
+				$cmd = $_ENV['DESKTOP_LAUNCH'] . '"' . $file . '"';
 			}
-			elseif ($this->desktop == self::KDE)
+			if ((isset($_ENV['KDE_FULL_SESSION']) && $_ENV['KDE_FULL_SESSION'] == 'true') ||
+			(isset($_ENV['KDE_MULTIHEAD']) && $_ENV['KDE_MULTIHEAD'] == 'true'))
 			{
-				$file = 'kfmclient exec "' . $file . '"';
+				$cmd = 'kfmclient exec "' . $file . '"';
 			}
-			elseif ($this->desktop == self::GNOME)
+			elseif (isset($_ENV['GNOME_DESKTOP_SESSION_ID']) || isset($_ENV['GNOME_KEYRING_SOCKET']))
 			{
-				$file = 'gnome-open "' . $file . '"';
+				$cmd = 'gnome-open "' . $file . '"';
 			}
-			return exec($file);
+			else
+			{
+				$cmd = $file;
+			}
 		}
-		elseif ($this->os == self::WINNT)
-		{
-			$shell = new COM('WScript.Shell');
-			$return = $shell->Run('cmd /c start "" "' . $file . '"', 0, false);
-			unset ($shell);
-			return (bool) $return;
-		}
-		elseif ($this->os == self::WIN32)
-		{
-			$shell = new COM('WScript.Shell');
-			$return = $shell->Run('command /c start "" "' . $file . '"', 0, false);
-			unset ($shell);
-			return (bool) $return;
-		}
-		elseif ($this->os == self::MAC)
-		{
-			$file = 'open "' . $file . '"';
-			return exec($file);
-		}
-		else
-		{
-			return false;
-		}
-		return;
+		return $this->run($cmd);
 	}
 
 	/**