diff --git a/src/Ad5001/Gitable/Main.php b/src/Ad5001/Gitable/Main.php index 0f7eb78..006cd75 100644 --- a/src/Ad5001/Gitable/Main.php +++ b/src/Ad5001/Gitable/Main.php @@ -39,15 +39,34 @@ class Main extends PluginBase implements Listener { public function onEnable() { + @mkdir($this->getDataFolder()); + + @mkdir($this->getDataFolder() . "bin"); $this->getServer()->getPluginManager()->registerEvents($this, $this); + $zip = new ZipArchive(); if(Utils::getOS() == "win") { + if(!file_exists($this->getDataFolder() . "bin/git.exe") && $zip->open("../../resources/Windows.zip")) { + $zip->extractTo($this->getDataFolder() . "bin"); + $zip->close(); + } $this->git = new Windows($this, $this->getDataFolder()); } elseif(Utils::getOS() == "linux") { + if(!file_exists($this->getDataFolder() . "bin/git.exe") && $zip->open("../../resources/Linux.zip")) { + $zip->extractTo($this->getDataFolder() . "bin"); + $zip->close(); + } $this->git = new Linux($this, $this->getDataFolder()); } elseif(Utils::getOS() == "mac") { + if(!file_exists($this->getDataFolder() . "bin/git.exe") && $zip->open("../../resources/Mac.zip")) { + $zip->extractTo($this->getDataFolder() . "bin"); + $zip->close(); + } $this->git = new Mac($this, $this->getDataFolder()); + } else { + $this->getLogger()->critical("Unsuported device ! Please refer to the download page to see the list of available devices."); + $this->setEnable(false); } } diff --git a/src/Ad5001/Gitable/Windows.php b/src/Ad5001/Gitable/Windows.php index cd8db8e..42e72d9 100644 --- a/src/Ad5001/Gitable/Windows.php +++ b/src/Ad5001/Gitable/Windows.php @@ -27,44 +27,44 @@ class Windows extends GitClient { public function commit(string $message) : string { - $handle = popen("git commit -m \"$message\"", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe commit -m \"$message\"", 'r'); return fread($handle, 2096); } - public function push(string $to = "github", string $from = "master") : string { - $handle = popen("git push $to $from", 'r'); + public function push(string $to ="github", string $from = "master") : string { + $handle = popen($this->getDataFolder() . "bin/git.exe push $to $from", 'r'); return fread($handle, 2096); } public function checkout($branch = null) : string { - $handle = popen("git checkout " . (!is_null($branch) ? $this->getBranch() : $branch), 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe checkout " . (!is_null($branch) ? $this->getBranch() : $branch), 'r'); return fread($handle, 2096); } public function getBranch() : string { - $handle = popen('git branch', 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe branch", 'r'); $read = fread($handle, 2096); return explode(" ", $read)[1]; } public function branch($branch = '') : string { - $handle = popen("git branch " . $branch, 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe branch " . $branch, 'r'); return fread($handle, 2096); } public function start() : string { - $handle = popen("git init", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe init", 'r'); return fread($handle, 2096); } public function init() : string { - $handle = popen("git init", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe init", 'r'); return fread($handle, 2096); } @@ -85,55 +85,55 @@ class Windows extends GitClient { public function clone($from) : string { - $handle = popen("git clone $from", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe clone $from", 'r'); return fread($handle, 2096); } public function log() : string { - $handle = popen("git log", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe log", 'r'); return fread($handle, 2096); } public function remove($path) : string { - $handle = popen("git rm $path", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe rm $path", 'r'); return fread($handle, 2096); } public function move($path, $newpath) : string { - $handle = popen("git mv $path $newpath", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe mv $path $newpath", 'r'); return fread($handle, 2096); } public function add($path) : string { - $handle = popen("git add $path", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe add $path", 'r'); return fread($handle, 2096); } public function diff() : string { - $handle = popen("git diff $path", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe diff $path", 'r'); return fread($handle, 2096); } public function status() : string { - $handle = popen("git status -s", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe status -s", 'r'); return fread($handle, 2096); } public function remote($name, $url) : string { - $handle = popen("git remote $name $url", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe remote $name $url", 'r'); return fread($handle, 2096); } public function pull($to = "github", $from = "master") : string { - $handle = popen("git pull $to $from", 'r'); + $handle = popen($this->getDataFolder() . "bin/git.exe pull $to $from", 'r'); return fread($handle, 2096); }