Example #1
0
        public static async Task BringUpToDate(string branch, string expectedVersion, string updateReason)
        {
            string currentVersion = versionRegistry.GetString("VersionGuid");

            if (currentVersion != expectedVersion)
            {
                DialogResult check = MessageBox.Show
                                     (
                    "Roblox Studio is out of date!\n"
                    + updateReason +
                    "\nWould you like to update now?",

                    "Out of date!",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning
                                     );

                if (check == DialogResult.Yes)
                {
                    RobloxStudioInstaller installer = new RobloxStudioInstaller(false);

                    await installer.RunInstaller(branch);

                    installer.Dispose();
                }
            }
        }
Example #2
0
        private async void launchStudio_Click(object sender = null, EventArgs e = null)
        {
            Hide();

            string branch = (string)branchSelect.SelectedItem;

            RobloxStudioInstaller installer = new RobloxStudioInstaller(forceRebuild.Checked);
            await installer.RunInstaller(branch);

            string studioRoot = RobloxStudioInstaller.GetStudioDirectory();
            string modPath    = getModPath();

            string[] studioFiles = Directory.GetFiles(studioRoot);
            string[] modFiles    = Directory.GetFiles(modPath, "*.*", SearchOption.AllDirectories);

            foreach (string modFile in modFiles)
            {
                try
                {
                    byte[]   fileContents   = File.ReadAllBytes(modFile);
                    FileInfo modFileControl = new FileInfo(modFile);

                    string relativeFile = modFile.Replace(modPath, studioRoot);
                    string relativeDir  = Directory
                                          .GetParent(relativeFile)
                                          .ToString();

                    if (!Directory.Exists(relativeDir))
                    {
                        Directory.CreateDirectory(relativeDir);
                    }

                    if (File.Exists(relativeFile))
                    {
                        byte[] relativeContents = File.ReadAllBytes(relativeFile);

                        if (!fileContents.SequenceEqual(relativeContents))
                        {
                            modFileControl.CopyTo(relativeFile, true);
                        }
                    }
                    else
                    {
                        File.WriteAllBytes(relativeFile, fileContents);
                    }
                }
                catch
                {
                    Console.WriteLine("Failed to overwrite {0}!", modFile);
                }
            }

            // Hack in the metadata plugin.
            // This is used to provide an end-point to custom StarterScripts that are trying to fork what branch they are on.
            // It creates a BindableFunction inside of the ScriptContext called GetModManagerBranch, which returns the branch set in the launcher.

            try
            {
                Assembly self = Assembly.GetExecutingAssembly();
                string   metaScript;

                using (Stream stream = self.GetManifestResourceStream("RobloxStudioModManager.Resources.ModManagerMetadata.lua"))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        metaScript = reader.ReadToEnd();
                        metaScript = metaScript.Replace("%MOD_MANAGER_VERSION%", '"' + branch + '"'); // TODO: Make this something more generic?
                    }

                string dir = Path.Combine(studioRoot, "BuiltInPlugins");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                string   metaScriptFile = Path.Combine(dir, "__rbxModManagerMetadata.lua");
                FileInfo info           = new FileInfo(metaScriptFile);

                if (info.Exists)
                {
                    info.Attributes = FileAttributes.Normal;
                }

                File.WriteAllText(metaScriptFile, metaScript);

                // Make the file as readonly so that it (hopefully) won't be messed with.
                // I can't hide the file because Roblox Studio will ignore it.
                // If someone has the file open with write permissions, it will fail to write.
                info.Attributes = FileAttributes.ReadOnly;
            }
            catch
            {
                Console.WriteLine("Failed to write __rbxModManagerMetadata.lua");
            }

            var robloxStudioInfo = new ProcessStartInfo();

            robloxStudioInfo.FileName = RobloxStudioInstaller.GetStudioPath();

            if (args != null)
            {
                string firstArg = args[0];

                if (firstArg != null && firstArg.StartsWith("roblox-studio"))
                {
                    // Arguments were passed by URI.
                    var argMap = new Dictionary <string, string>();

                    foreach (string commandPair in firstArg.Split('+'))
                    {
                        if (commandPair.Contains(':'))
                        {
                            string[] kvPair = commandPair.Split(':');

                            string key = kvPair[0];
                            string val = kvPair[1];

                            if (key == "gameinfo")
                            {
                                // The user is authenticating. This argument is a special case.
                                robloxStudioInfo.Arguments += " -url https://www.roblox.com/Login/Negotiate.ashx -ticket " + val;
                            }
                            else
                            {
                                argMap.Add(key, val);
                                robloxStudioInfo.Arguments += " -" + key + ' ' + val;
                            }
                        }
                    }

                    if (argMap.ContainsKey("launchmode") && !argMap.ContainsKey("task"))
                    {
                        robloxStudioInfo.Arguments += "-task ";

                        string launchMode = argMap["launchmode"];
                        string addToArgs  = "";

                        if (launchMode == "plugin")
                        {
                            addToArgs = "InstallPlugin";
                        }
                        else if (launchMode == "edit")
                        {
                            addToArgs = "EditPlace";
                        }

                        robloxStudioInfo.Arguments += addToArgs;
                    }
                }
                else
                {
                    // Arguments were passed directly.
                    string fullArg = string.Join(" ", args);
                    robloxStudioInfo.Arguments += fullArg;
                }
            }

            if (openStudioDirectory.Checked)
            {
                Process.Start(studioRoot);
            }
            else
            {
                string currentVersion = versionRegistry.GetString("VersionGuid");
                versionRegistry.SetValue("LastExecutedVersion", currentVersion);

                Process.Start(robloxStudioInfo);
            }

            Environment.Exit(0);
        }