Ejemplo n.º 1
0
        public void FlushConfig()
        {
            string text = "";

            foreach (KeyValuePair <string, string> pair in data)
            {
                text = text + pair.Key + " \"" + pair.Value.Replace("\"", "\\\"") + "\"";
                if (Updater.IsLoonix())
                {
                    text = text + "\n";
                }
                else
                {
                    text = text + "\r\n";
                }
            }
            File.WriteAllText(path, text);
        }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            variables = new VarStorage();
            variables.SetValue("version", version);
            ConsoleLogger.debugscreen = new DebugScr();
            ConsoleLogger.debugscreen.Show();
            bool   hide  = true;
            string chdir = "";

            if ((File.Exists("ll-debugme")) || (File.Exists("ll-debugme.txt")))
            {
                hide = false;
            }
            if (Environment.GetCommandLineArgs().Length >= 2)
            {
                string[] cmdline = Environment.GetCommandLineArgs();
                int      i       = 1;
                while (i < cmdline.Length)
                {
                    if (cmdline[i] == "--debug")
                    {
                        hide = false;
                    }
                    else if (cmdline[i] == "--dir")
                    {
                        chdir = cmdline[(i + 1)];
                    }
                    i++;
                }
            }
            if (hide)
            {
                ConsoleLogger.debugscreen.Hide();
            }
            this.KeyPreview = true;
            ConsoleLogger.LogData("LL " + Form1.version + " @ " + Environment.GetCommandLineArgs()[0], "Main");
            ConsoleLogger.LogData("Environment fingerprint: " + getFingerprint());
            dec     = -50;
            offline = false;
            hasjava = false;
            Updater upd = new Updater(".");

            loonix = Updater.IsLoonix();
            string os = "Windoze";

            javaname = "java";
            string fd = "\\";

            if (loonix)
            {
                fd = "/";
                os = "Linux";
            }
            variables.SetValue("fd", fd);
            string installpath = "";
            string tempdir     = "";

            if (!loonix)
            {
                installpath = Environment.GetEnvironmentVariable("APPDATA") + fd + "LameCraft";
                tempdir     = Environment.GetEnvironmentVariable("TEMP");
            }
            else
            {
                installpath = Environment.GetEnvironmentVariable("HOME") + fd + ".LameCraft";
                tempdir     = "/tmp";
            }
            if (chdir != "")
            {
                installpath = chdir;
            }
            variables.SetValue("lldir", installpath);
            ConsoleLogger.LogData("OS: " + os, "Main");
            ConsoleLogger.LogData("MCIP: " + installpath, "Main");
            ConsoleLogger.LogData("TMP: " + tempdir, "Main");
            if (!Directory.Exists(installpath))
            {
                Directory.CreateDirectory(installpath);
            }
            Directory.SetCurrentDirectory(installpath);
            config            = new ConfigFile("launcher.cfg");
            label4.Text       = "LameLauncher version: " + version + ", Minecraft: " + upd.GetCurrentVersion() + ", " + os;
            button3.Location  = new Point(button3.Location.X + 400, button3.Location.Y);
            button2.Location  = new Point(button2.Location.X + 400, button2.Location.Y);
            label5.Location   = new Point(label5.Location.X + 400, label5.Location.Y);
            textBox3.Location = new Point(textBox3.Location.X + 400, textBox3.Location.Y);
            DetectJava();
            if (hasjava)
            {
                label6.Hide();
            }
            if (config.GetValue("offlinemode", "0") == "0")
            {
                try
                {
                    ConsoleLogger.LogData("Cekiram dosegljivost auth serverja...", "Main");
                    upd.GetHTTPFile("https://minecraft.knuples.net/auth.php?ping=1", tempdir + fd + "deleteme.mclauncher.auth.chk", 1500);
                    File.Delete(tempdir + fd + "deleteme.mclauncher.update.chk");
                }
                catch (Exception e)
                {
                    ConsoleLogger.LogData("*** AUTH SERVER NEDOSEGLJIV ***", "Main");
                    ConsoleLogger.LogData(e.Message, "Main");
                    ConsoleLogger.LogData("Delujem v offline nacinu!", "Main");
                    offline = true;
                }
                if ((config.GetValue("chkupdate", "1") == "1") && (!offline))
                {
                    bool isupdate = false;
                    try
                    {
                        // This is so important, we can't mess this up!
                        ConsoleLogger.LogData("Cekiram za update launcherja...", "Main");
                        upd.GetHTTPFile("https://minecraft.knuples.net/updates/launcher/" + version + "." + os, tempdir + fd + "deleteme.mclauncher.update.chk" + version, 300, 1);
                        File.Delete(tempdir + fd + "deleteme.mclauncher.update.chk");
                        UpdateWindow uw = new UpdateWindow();
                        uw.NewStatus("Launcher ima nov update, downloadam...");
                        ConsoleLogger.LogData("Launcher ima nov update!", "Main");
                        isupdate     = true;
                        uw.runthread = false;
                        uw.Show();
                        Application.DoEvents();
                        string ofile = tempdir + fd + "deleteme." + version + "mclauncher.update.exe";
                        Application.DoEvents();
                        upd.GetHTTPFile("https://minecraft.knuples.net/updates/launcher/" + version + "." + os + ".bin", ofile, 1000);
                        uw.Hide();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                        startInfo.FileName    = ofile;
                        startInfo.Arguments   = Environment.GetCommandLineArgs()[0];
                        System.Diagnostics.Process proc = new System.Diagnostics.Process();
                        proc.StartInfo = startInfo;
                        proc.Start();
                        Application.Exit();
                        Environment.Exit(0);
                    }
                    catch {
                        /** WTF JE BLO TO, SHIT, SHIT, SHIT, DO TEGA NEBI SMELO PRIT!
                         *  Konec je z nami, fertik smo, adijo, zbrisi system32 in zvali krivdo
                         *  na Windowse. Po možnosti poišči še vse .doc in .jpg fajle in jih zbriši,
                         *  da se bo mel user za kaj sekirat, razen tega kak ne more minecrafta igrat **/
                        if (isupdate)
                        {
                            MessageBox.Show("Poskusal downloadat update, ampak mi nekako ni uspelo.\nProsim, prenesi update s strani!");
                            Environment.Exit(1);
                        }
                        /* Ali pa crashni aplikacijo. Jup, to bi tudi šlo. */
                        Application.Exit();
                    }
                    int ntries = 0;
                    while (testForMinecraftUpdate(upd))
                    {
                        ntries++;
                        ConsoleLogger.LogData("Retesting for update...");
                        if (ntries > 10)
                        {
                            MessageBox.Show("Dal že deset iteracij poskusa updejta skozi. Nekaj je hudo narobe.\nProsim kontaktiraj admine!");
                            Application.Exit();
                            Environment.Exit(0);
                        }
                    }
                }
            }
            else
            {
                ConsoleLogger.LogData("Hoces offline nacin? Tudi prav!", "Main");
                offline = true;
            }
            if (offline)
            {
                checkBox2.Visible  = false;
                linkLabel1.Visible = false;
                label7.Visible     = true;
                checkBox1.Location = new Point(171, checkBox1.Location.Y);
            }
            if (config.GetValue("remember", "1") == "1")
            {
                textBox1.Text     = config.GetValue("user", "");
                textBox2.Text     = config.GetValue("pass", "");
                checkBox1.Checked = true;
            }
            if (config.GetValue("autologin", "1") == "1")
            {
                checkBox2.Checked = true;
            }
            ConsoleLogger.LogData("Init koncan, fire away!", "Main");
        }
Ejemplo n.º 3
0
 public void ExecuteCode(string[] code, bool close_window)
 {
     foreach (string line in code)
     {
         if (progress)
         {
             this.updwindow.Invoke(updwindow.newtick);
         }
         List <string> commands = TokenizeLine(line);
         if (commands[0] == "--")
         {
             continue;
         }
         bool canfail = false;
         if (commands[0] == "CANFAIL")
         {
             canfail = true;
             commands.RemoveAt(0);
         }
         if (commands[0] == "IFLOONIX")
         {
             commands.RemoveAt(0);
             if (!Updater.IsLoonix())
             {
                 continue;
             }
         }
         if (commands[0] == "IFWIN")
         {
             commands.RemoveAt(0);
             if (Updater.IsLoonix())
             {
                 continue;
             }
         }
         try
         {
             if (commands[0] == "EXECUTE")
             {
                 this.UpdateStatus("Zaganjam command file " + commands[1]);
                 this.ExecuteCode(commands[1], false, false);
                 if ((progress) && (this.updwindow.update_error != ""))
                 {
                     throw new Exception(this.updwindow.update_error);
                 }
             }
             if (commands[0] == "VERIFY")
             {
                 this.UpdateStatus("Verifying file " + commands[1]);
                 if (this.GetSHAHashFromFile(commands[1]) != commands[2])
                 {
                     throw new Exception("Datoteka " + commands[1] + " zgleda da je bila nepričakovano spremenjena!");
                 }
             }
             if (commands[0] == "EXTRACT")
             {
                 this.UpdateStatus("Extractam file '" + commands[2] + "' iz '" + commands[1] + "' v '" + commands[3] + "'");
                 ZipStorer zip = ZipStorer.Open(commands[1], FileAccess.Read);
                 List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                 bool success = false;
                 foreach (ZipStorer.ZipFileEntry entry in dir)
                 {
                     if (entry.FilenameInZip == commands[2])
                     {
                         zip.ExtractFile(entry, commands[3]);
                         success = true;
                         break;
                     }
                 }
                 if (!success)
                 {
                     throw new Exception("Datoteka " + commands[1] + "/" + commands[2] + " ne obstaja!");
                 }
                 zip.Close();
             }
             if (commands[0] == "ADD")
             {
                 bool shamatch = false;
                 if (File.Exists(commands[1]))
                 {
                     string shasum = this.GetSHAHashFromFile(commands[1]);
                     if (shasum == commands[2])
                     {
                         shamatch = true;
                     }
                 }
                 if (shamatch)
                 {
                     this.UpdateStatus("Ze imam fajl: " + commands[1] + ", skip...");
                     continue;
                 }
                 DownloadFile(commands[1], commands[1]);
             }
             if (commands[0] == "SET")
             {
                 this.SetVar(commands[1], commands[2]);
             }
             if (commands[0] == "CLEARMIRRORS")
             {
                 this.UpdateStatus("Spucal vse mirrorje");
                 this.mirrorlist.Clear();
                 this.mirrors.Clear();
             }
             if (commands[0] == "MIRROR")
             {
                 this.mirrors.Add(commands[1], commands[2]);
                 this.mirrorlist.Add(commands[1]);
                 this.UpdateStatus("Dodajam nov mirror: " + commands[2] + ", ID: " + this.FindMirrorIndex(commands[1]).ToString());
             }
             if (commands[0] == "MKDIR")
             {
                 this.UpdateStatus("Ustvarjam mapo " + commands[1]);
                 Directory.CreateDirectory(commands[1]);
             }
             if (commands[0] == "DEL")
             {
                 this.UpdateStatus("Brisem " + commands[1]);
                 if (Directory.Exists(commands[1]))
                 {
                     Directory.Delete(commands[1], true);
                 }
                 else
                 {
                     File.Delete(commands[1]);
                 }
             }
             if (commands[0] == "COMMIT")
             {
                 this.UpdateStatus("Koncujem update...");
                 File.WriteAllText("cversion", this.GetVar("VERSION"));
                 this.UpdateStatus("Done");
             }
             if (commands[0] == "OVERRIDE")
             {
                 try
                 {
                     this.UpdateStatus("Dodajam override za " + commands[1] + "...");
                     overrides.Add(commands[1], commands[2]);
                 }
                 catch { };
             }
             if (commands[0] == "SETCFG")
             {
                 Form1.config.SetValue(commands[1], commands[2]);
                 Form1.config.FlushConfig();
             }
             if (commands[0] == "RENAME")
             {
                 File.Move(commands[1], commands[2]);
             }
             if (commands[0] == "RESTART")
             {
                 System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                 startInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                 startInfo.FileName        = commands[1];
                 startInfo.UseShellExecute = true;
                 process.StartInfo         = startInfo;
                 process.Start();
                 Environment.Exit(0);
             }
         }
         catch (Exception e)
         {
             if (progress)
             {
                 this.UpdateStatus("ERROR: " + e.Message);
             }
             if (!canfail)
             {
                 System.Threading.Thread.Sleep(1000);
                 if (progress)
                 {
                     this.progress = false;
                     this.updwindow.Invoke(updwindow.weredone);
                 }
                 this.updwindow.update_error = e.Message;
                 return;
             }
         }
     }
     if ((progress) && (close_window))
     {
         System.Threading.Thread.Sleep(1000);
         this.updwindow.update_success = true;
         this.updwindow.Invoke(updwindow.weredone);
     }
 }