Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* external_controls by Flammrock, used for download all external controls here : http://batch-external-controls.site88.net/list.php */
- /* Under MIT/X11 licence. */
- /*
- The MIT License (MIT)
- Copyright (c) 2016 Flammrock
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- */
- using System;
- using System.Net;
- using System.IO;
- using System.Diagnostics;
- namespace gate
- {
- class Program
- {
- static void Main(string[] args)
- {
- ConsoleColor oldFGcolor = Console.ForegroundColor;
- String temp = Path.GetTempPath();
- string start_1_a = "\"";
- string start_1_b = "GATE";
- string start_1_c = "\" a été créé par ";
- string start_1_d = "Flammrock";
- string start_2_a = "Copyright (c) 2016 ";
- string start_2_b = "Flammrock";
- string start_3 = "Création des portails en cours...";
- string start_4 = "Veuillez patienter...\n";
- Console.SetCursorPosition(0, 2);
- var y = 0;
- while (y < Console.WindowWidth / 2) { Console.Write("_"); y++; }
- Console.SetCursorPosition(((Console.WindowWidth / 2) - (start_1_a.Length + start_1_b.Length + start_1_c.Length + start_1_d.Length)), 3);
- Console.ForegroundColor = oldFGcolor;
- Console.Write(start_1_a);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(start_1_b);
- Console.ForegroundColor = oldFGcolor;
- Console.Write(start_1_c);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(start_1_d);
- Console.SetCursorPosition(((Console.WindowWidth / 2) - (start_2_a.Length + start_2_b.Length)), 4);
- Console.ForegroundColor = oldFGcolor;
- Console.Write(start_2_a);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(start_2_b);
- Console.ForegroundColor = oldFGcolor;
- Console.SetCursorPosition(((Console.WindowWidth / 2) - start_3.Length), 6);
- Console.Write(start_3);
- Console.SetCursorPosition(((Console.WindowWidth / 2) - start_4.Length)+1, 7);
- Console.Write(start_4);
- if (WebRequestTest())
- {
- string start_5 = "Portails créés avec succès !\n";
- Console.SetCursorPosition(((Console.WindowWidth / 2) - start_5.Length), 8);
- Console.Write(start_5);
- y = 0;
- while (y < Console.WindowWidth / 2) { Console.Write("¯"); y++; }
- Console.Write("\n\n\n");
- var i = 0;
- while (i < args.Length)
- {
- if (args[i] == "/hide")
- {
- Console.SetOut(TextWriter.Null);
- Console.SetError(TextWriter.Null);
- }
- i++;
- }
- if (args.Length <= 1)
- {
- WriteError("Erreur de syntaxe !");
- Environment.Exit(0);
- }
- else if (args[0] == "/start")
- {
- Process.Start(args[1]);
- }
- if (args[0] == "/?" || args[0] == "/help")
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- Aide Commande externe 'GATE' -------\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /? : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Affiche l'aide et la liste des commandes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /list : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet d'afficher la liste des commandes externes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /start : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet d'exécuter des fichiers.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /get /? : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Affiche l'aide et la liste des commandes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /get <commande_externe> : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet de télécharger n'importe quel commande externe.\n");
- Console.Write(" Exemple : get SockeT_full\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /get /list : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet d'afficher la liste des commandes externes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /send /? : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Affiche l'aide et la liste des commandes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /send <commande_externe> : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet de téléverser n'importe quel commande externe.\n");
- Console.Write(" Exemple : send SockeT_full\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("gate /send /list : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet d'afficher la liste des commandes externes.\n");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- 'GATE' a été créé par Flammrock -------\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\n");
- Environment.Exit(0);
- }
- else if (args[0] == "/list")
- {
- Console.Write("Connexion sur le serveur en cours...\n");
- list_file();
- Environment.Exit(0);
- }
- else if (args[0] == "/send")
- {
- if (args[1] == "/?")
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- Aide Commande externe 'Send' -------\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("send /? : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Affiche l'aide et la liste des commandes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("send <commande_externe> : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet de téléverser n'importe quel commande externe.\n");
- Console.Write(" Exemple : send SockeT_full\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("send /list : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet d'afficher la liste des commandes externes.\n");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- 'Send' a été créé par Flammrock -------\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\n");
- Environment.Exit(0);
- }
- else if (args[1] == "/list")
- {
- Console.Write("Connexion sur le serveur en cours...\n");
- list_file();
- Environment.Exit(0);
- }
- else
- {
- if (args.Length > 2)
- {
- WriteError("Erreur de syntaxe !");
- }
- else
- {
- if (args[1] == "/upload")
- {
- Console.Write("Connexion sur le serveur en cours...\n");
- string add = "<html><head><title>Ajout d'une commande externe en cours !</title><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"><script>window.resizeTo(800,800);var largeur=screen.availWidth;var hauteur=screen.availHeight;var demiL=((largeur-800)/2); var demiH=((hauteur-800)/2); window.moveTo(demiL,demiH);</script></head><body><iframe src=\"http://batch-external-controls.site88.net/add_c.html\" style=\"position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;\"></body></html>";
- StreamWriter addfile = new StreamWriter(temp + "add.hta");
- addfile.WriteLine(add);
- addfile.Close();
- Process.Start(temp + "add.hta");
- Console.Write("Veuillez remplir le formulaire !\n");
- }
- }
- }
- }
- else if (args[0] == "/get")
- {
- if (args[1] == "/?")
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- Aide Commande externe 'Get' -------\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("get /? : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Affiche l'aide et la liste des commandes.\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("get <commande_externe> : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet de télécharger n'importe quel commande externe.\n");
- Console.Write(" Exemple : get SockeT_full\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("get /list : ");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write("Permet d'afficher la liste des commandes externes.\n");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- 'Get' a été créé par Flammrock -------\n");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\n");
- Environment.Exit(0);
- }
- else if (args[1] == "/list")
- {
- Console.Write("Connexion sur le serveur en cours...\n");
- list_file();
- Environment.Exit(0);
- }
- else if (args[1] == "/version")
- {
- String current_version_all = args[2];
- String[] current_version_split = current_version_all.Split(':');
- String current_version_command = current_version_split[0];
- if (current_version_command == "-CurrentVersion")
- {
- try
- {
- String current_version = current_version_split[1];
- String external_command = args[3];
- String external_command_MIN = args[3].ToLower();
- String external_command_name = external_command.Remove(0, 1);
- String external_command_name_MIN = external_command_MIN.Remove(0, 1);
- String real_last_version_MIN = "0";
- String real_current_version_MIN = "1";
- Console.Write("Recherche d'une mise à jour pour ");
- Console.Write("\"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\"\n");
- Console.WriteLine("Connexion au serveur..");
- string _url = "http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + ".php";
- if (CheckUrl(_url) == "OK")
- {
- Console.Write("\"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\" existe\n");
- WebClient wc = new WebClient();
- wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + "-ext" + ".php", temp + "ext.php");
- wc.Dispose();
- String file_ext = temp + "ext.php";
- StreamReader file_ex = new StreamReader(file_ext);
- String ext = file_ex.ReadLine();
- file_ex.Close();
- wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + "-version" + ".php", temp + "version.php");
- wc.Dispose();
- String file_version = temp + "version.php";
- StreamReader file = new StreamReader(file_version);
- String last_version = file.ReadLine();
- file.Close();
- real_current_version_MIN = current_version.ToLower();
- String real_current_version = real_current_version_MIN.Trim(new Char[] { '"' });
- real_last_version_MIN = last_version.ToLower();
- Console.WriteLine("\nVersion sur le serveur : ");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("{0}\n", real_last_version_MIN);
- Console.ForegroundColor = oldFGcolor;
- Console.WriteLine("Version sur votre PC : ");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("{0}\n\n", real_current_version);
- Console.ForegroundColor = oldFGcolor;
- if (real_last_version_MIN == real_current_version)
- {
- Console.WriteLine("Vous possédez la dernière version de {0}", external_command_name);
- Environment.Exit(0);
- }
- else
- {
- Console.WriteLine("Vous ne possédez pas la dernière version de {0}", external_command_name);
- String command_install = args[4].Substring(0, 8);
- String command_download = args[4].Substring(0, 9);
- if (command_install == "/install")
- {
- String[] name_install = args[4].Split(':');
- String current_name_file = name_install[1];
- String new_line = "set \"version_" + external_command_name_MIN + "=" + real_last_version_MIN + "\"";
- try
- {
- Read_file(external_command_name_MIN, external_command_name, "0", "generate_ex");
- install_file(current_name_file, new_line, external_command_name_MIN);
- Environment.Exit(0);
- }
- catch
- {
- WriteError("Erreur lors de l'installation !\n");
- Environment.Exit(0);
- }
- }
- else if (command_download == "/download")
- {
- try
- {
- WebClient try_wc = new WebClient();
- try_wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + ".ini", external_command_name_MIN + ext);
- try_wc.Dispose();
- Console.Write("Téléchargement terminé !\n");
- try
- {
- String[] name_download = args[4].Split(':');
- String path = name_download[1];
- String path_copy = path + "-install";
- if (File.Exists(path_copy)) { File.Delete(path_copy); }
- File.Copy(path, path_copy);
- String final_file = null;
- StreamReader sr = new StreamReader(path_copy);
- String new_line = "set \"version_" + external_command_name_MIN + "=" + real_last_version_MIN + "\"";
- String line_read = null;
- String find_line = null;
- while (!sr.EndOfStream)
- {
- line_read = sr.ReadLine();
- if (line_read.Length >= 13 + external_command_name_MIN.Length)
- {
- find_line = line_read.Substring(0, 13 + external_command_name_MIN.Length);
- }
- if (find_line == "set \"version_" + external_command_name_MIN)
- {
- if (!sr.EndOfStream)
- {
- final_file = (final_file + (new_line + "\r\n"));
- }
- else
- {
- final_file = (final_file + (new_line));
- }
- }
- else
- {
- if (!sr.EndOfStream)
- {
- final_file = (final_file + (line_read + "\r\n"));
- }
- else
- {
- final_file = (final_file + (line_read));
- }
- }
- }
- sr.Close();
- StreamWriter sr2 = new StreamWriter(path_copy);
- sr2.WriteLine(final_file);
- sr2.Close();
- String lines = "@ping localhost -n 2 >nul \r\ndel \"" + path + "\"\r\nren \"" + path_copy + "\" \"" + path + "\"\r\ngate /start \"" + path + "\"\r\ndel GATE_Install.bat";
- StreamWriter file_install = new StreamWriter("GATE_Install.bat");
- file_install.WriteLine(lines);
- file_install.Close();
- Process[] myProcesses;
- myProcesses = Process.GetProcessesByName("cmd");
- foreach (Process myProcess in myProcesses)
- {
- Console.WriteLine("Installation terminée !");
- Process.Start("GATE_Install.bat");
- myProcess.CloseMainWindow();
- }
- }
- catch
- {
- WriteError("Erreur lors de l'installation !\n");
- Environment.Exit(0);
- }
- }
- catch
- {
- WriteError("Erreur lors du téléchargement !\n");
- Environment.Exit(0);
- }
- }
- else
- {
- WriteError("Erreur de syntaxe !");
- Environment.Exit(0);
- }
- }
- }
- else
- {
- WriteError("La connexion sur le serveur a échoué !\n Le serveur est en maintenance !\nVeuillez réassyer réessayer ultérieurement !");
- Environment.Exit(0);
- }
- }
- catch
- {
- WriteError("Erreur de syntaxe !");
- Environment.Exit(0);
- }
- }
- else
- {
- try
- {
- String string_test_arg2 = args[3];
- WriteError("Erreur de syntaxe !");
- Environment.Exit(0);
- }
- catch
- {
- String external_command_MIN = args[2].ToLower();
- String external_command = args[2];
- String external_command_name = external_command.Remove(0, 1);
- String external_command_name_MIN = external_command_MIN.Remove(0, 1);
- Console.Write("Recherche d'une mise à jour pour ");
- Console.Write("\"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\"\n");
- Console.WriteLine("Connexion au serveur..");
- string _url = "http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + ".php";
- if (CheckUrl(_url) == "OK")
- {
- Console.Write("\"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\" existe\n");
- Read_file(external_command_name_MIN, external_command_name, "0", "version");
- Environment.Exit(0);
- }
- else
- {
- WriteError("Cette commande externe n'existe pas !");
- Environment.Exit(0);
- }
- }
- }
- }
- else
- {
- try
- {
- String string_test_arg1 = args[2];
- WriteError("Erreur de syntaxe !");
- Environment.Exit(0);
- }
- catch
- {
- Download_file(args[1]);
- }
- }
- }
- else if (args[0] == "/download")
- {
- String RemoteFtpPath = args[1];
- String LocalDestinationPath = args[2];
- String Username = args[3];
- String Password = args[4];
- try
- {
- Boolean UseBinary = true;
- Boolean UsePassive = false;
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create(RemoteFtpPath);
- request.Method = WebRequestMethods.Ftp.DownloadFile;
- request.KeepAlive = true;
- request.UsePassive = UsePassive;
- request.UseBinary = UseBinary;
- request.Credentials = new NetworkCredential(Username, Password);
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Stream responseStream = response.GetResponseStream();
- StreamReader reader = new StreamReader(responseStream);
- using (FileStream writer = new FileStream(LocalDestinationPath, FileMode.Create))
- {
- long length = response.ContentLength;
- int bufferSize = 2048;
- int readCount;
- byte[] buffer = new byte[2048];
- readCount = responseStream.Read(buffer, 0, bufferSize);
- while (readCount > 0)
- {
- writer.Write(buffer, 0, readCount);
- readCount = responseStream.Read(buffer, 0, bufferSize);
- }
- }
- reader.Close();
- response.Close();
- Environment.Exit(1);
- }
- catch
- {
- Environment.Exit(0);
- }
- }
- else if (args[0] == "/upload")
- {
- String source = args[1];
- String ftpurl = args[2];
- String ftpusername = args[3];
- String ftppassword = args[4];
- try
- {
- string filename = Path.GetFileName(source);
- string ftpfullpath = ftpurl;
- FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
- ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
- ftp.KeepAlive = true;
- ftp.UseBinary = true;
- ftp.Method = WebRequestMethods.Ftp.UploadFile;
- FileStream fs = File.OpenRead(source);
- byte[] buffer = new byte[fs.Length];
- fs.Read(buffer, 0, buffer.Length);
- fs.Close();
- Stream ftpstream = ftp.GetRequestStream();
- ftpstream.Write(buffer, 0, buffer.Length);
- ftpstream.Close();
- Environment.Exit(1);
- }
- catch
- {
- Environment.Exit(0);
- }
- }
- Environment.Exit(2);
- }
- else
- {
- string start_5 = "Echec création des portails !\n";
- Console.SetCursorPosition(((Console.WindowWidth / 2) - start_5.Length), 8);
- Console.Write(start_5);
- y = 0;
- while (y < Console.WindowWidth / 2) { Console.Write("¯"); y++; }
- Console.Write("\n\n\n");
- WriteError("La connexion au serveur a échoué !");
- WriteError("Veuillez vérifier votre connexion internet !");
- }
- }
- static string CheckUrl(string myUrl)
- {
- HttpWebRequest _Request;
- HttpWebResponse _Response;
- string message = "";
- if (myUrl != "")
- {
- try
- {
- _Request = (HttpWebRequest)WebRequest.Create(myUrl);
- _Request.AllowAutoRedirect = false;
- _Response = (HttpWebResponse)_Request.GetResponse();
- message = _Response.StatusCode.ToString();
- }
- catch (WebException ex)
- {
- if (ex.Response != null)
- {
- message = (((HttpWebResponse)ex.Response).StatusCode).ToString();
- }
- else
- message = ex.Message;
- }
- catch (UriFormatException ex1)
- {
- message = ex1.Message;
- }
- }
- return message;
- }
- static void list_file()
- {
- ConsoleColor oldFGcolor = Console.ForegroundColor;
- String temp = Path.GetTempPath();
- try
- {
- WebClient wc = new WebClient();
- wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/list.external_controls.php", temp + "list.external_controls.php");
- wc.Dispose();
- int counter = 0;
- string line;
- string file_list = temp + "list.external_controls.php";
- StreamReader file = new StreamReader(file_list);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("------- Liste des commandes externes disponibles :\n");
- Console.ForegroundColor = ConsoleColor.Blue;
- while ((line = file.ReadLine()) != null)
- {
- Console.WriteLine(line);
- counter++;
- }
- Console.ForegroundColor = ConsoleColor.Red;
- file.Close();
- File.Delete(file_list);
- Console.Write("\n");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("{0}", counter);
- Console.ForegroundColor = oldFGcolor;
- Console.Write(" commande externe disponible sur le serveur !\n\n");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("--------------------------------------------------\n");
- Console.ForegroundColor = oldFGcolor;
- }
- catch
- {
- WriteError("Erreur de connexion sur le serveur ! Veuillez réessayer !");
- Environment.Exit(0);
- }
- }
- static void Read_file(String external_command_name_MIN, String external_command_name, String mode, String information)
- {
- ConsoleColor oldFGcolor = Console.ForegroundColor;
- String temp = Path.GetTempPath();
- try
- {
- WebClient wc = new WebClient();
- wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + "-" + information + ".php", temp + information + ".php");
- wc.Dispose();
- String file_version = temp + information + ".php";
- if (information == "version")
- {
- StreamReader file = new StreamReader(file_version);
- String last_version = file.ReadLine();
- file.Close();
- if (mode == "0")
- {
- Console.Write("Version de \"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\" : ");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("{0}\n", last_version);
- Console.ForegroundColor = oldFGcolor;
- }
- }
- }
- catch
- {
- WriteError("Impossible de récupérer la version ! La connexion au serveur a échoué !");
- Environment.Exit(0);
- }
- }
- static void Download_file(string external_command)
- {
- ConsoleColor oldFGcolor = Console.ForegroundColor;
- String temp = Path.GetTempPath();
- WebClient wc = new WebClient();
- String external_command_MIN = external_command.ToLower();
- String external_command_name = external_command.Remove(0, 1);
- String external_command_name_MIN = external_command_MIN.Remove(0, 1);
- String external_command_ = external_command.ToLower();
- wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + "-ext" + ".php", temp + "ext.php");
- wc.Dispose();
- String file_ext = temp + "ext.php";
- StreamReader file_ex = new StreamReader(file_ext);
- String ext = file_ex.ReadLine();
- file_ex.Close();
- Console.Write("Recherche de \"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\" sur le serveur...\n");
- String _url = "http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + ".php";
- if (CheckUrl(_url) == "OK")
- {
- Console.Write("\"");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(external_command_name);
- Console.ForegroundColor = oldFGcolor;
- Console.Write("\" existe\n");
- try
- {
- wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + external_command_name_MIN + ".ini", external_command_name_MIN + ext);
- wc.Dispose();
- Console.Write("Téléchargement terminé !");
- Environment.Exit(0);
- }
- catch
- {
- WriteError("Erreur lors du téléchargement !");
- Environment.Exit(0);
- }
- }
- else
- {
- WriteError("Cette commande externe n'existe pas !");
- Console.ReadKey();
- }
- }
- static void WriteError(string msg, params object[] objs)
- {
- var oldFGcolor = Console.ForegroundColor;
- Console.Write("[");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("ERROR");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("] : ");
- Console.WriteLine(msg, objs);
- }
- static void WriteInfo(string msg, params object[] objs)
- {
- var oldFGcolor = Console.ForegroundColor;
- Console.Write("[");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write("INFO");
- Console.ForegroundColor = oldFGcolor;
- Console.Write("] : ");
- Console.WriteLine(msg, objs);
- }
- public static bool WebRequestTest()
- {
- string url = "http://www.google.com";
- try
- {
- System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url);
- System.Net.WebResponse myResponse = myRequest.GetResponse();
- }
- catch (System.Net.WebException)
- {
- return false;
- }
- return true;
- }
- static void install_file(string path, string new_line, string external_control)
- {
- Console.WriteLine("Installation en cours..");
- try
- {
- String temp = Path.GetTempPath();
- String path_copy = path+"-install";
- if (File.Exists(path_copy)) { File.Delete(path_copy); }
- File.Copy(path, path_copy);
- String final_file = null;
- StreamReader sr = new StreamReader(path_copy);
- String line_read = null;
- String find_line = null;
- String line_read_ = null;
- bool install_generate_code = false;
- while (!sr.EndOfStream)
- {
- line_read = sr.ReadLine();
- if (line_read.Length >= 13 + external_control.Length)
- {
- find_line = line_read.Substring(0, 13 + external_control.Length);
- }
- if (line_read == ":End_GATE_install_" + external_control)
- {
- install_generate_code = false;
- }
- else
- {
- if (line_read == ":GATE_install_" + external_control)
- {
- install_generate_code = true;
- final_file = (final_file + (line_read + "\r\n"));
- StreamReader file_ = new StreamReader(temp + "generate_ex.php");
- while (!file_.EndOfStream)
- {
- line_read_ = file_.ReadLine();
- final_file = (final_file + (line_read_ + "\r\n"));
- }
- file_.Close();
- final_file = (final_file + (":End_GATE_install_" + external_control));
- }
- else
- {
- if (!install_generate_code)
- {
- if (find_line == "set \"version_" + external_control)
- {
- if (!sr.EndOfStream)
- {
- final_file = (final_file + (new_line + "\r\n"));
- }
- else
- {
- final_file = (final_file + (new_line));
- }
- }
- else
- {
- if (!sr.EndOfStream)
- {
- final_file = (final_file + (line_read + "\r\n"));
- }
- else
- {
- final_file = (final_file + (line_read));
- }
- }
- }
- }
- }
- }
- sr.Close();
- StreamWriter sr2 = new StreamWriter(path_copy);
- sr2.WriteLine(final_file);
- sr2.Close();
- String lines = "@ping localhost -n 2 >nul \r\ndel \"" + path + "\"\r\nren \"" + path_copy + "\" \"" + path + "\"\r\ngate /start \"" + path + "\"\r\ndel GATE_Install.bat";
- StreamWriter file_install = new StreamWriter("GATE_Install.bat");
- file_install.WriteLine(lines);
- file_install.Close();
- Process[] myProcesses;
- myProcesses = Process.GetProcessesByName("cmd");
- foreach (Process myProcess in myProcesses)
- {
- Console.WriteLine("Installation terminée !");
- Process.Start("GATE_Install.bat");
- myProcess.CloseMainWindow();
- }
- }
- catch (Exception e)
- {
- WriteError("Echec de l'installation de la nouvelle version, veuillez vérifier la syntaxe de la commande.");
- Console.WriteLine(e);
- Environment.Exit(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement