Example #1
0
        /// <summary>
        /// Updte Visual Studio Code Launch file
        /// </summary>
        static void UpdateLaunchFile(int port)
        {
            //TODO Eventually all this JSON can be replaced with intragrated JSON

            // Create Default Config
            SimpleJSON.JSONClass defaultClass = new SimpleJSON.JSONClass();
            defaultClass ["name"]              = "Unity";
            defaultClass ["type"]              = "mono";
            defaultClass ["address"]           = "localhost";
            defaultClass ["port"].AsInt        = port;
            defaultClass ["sourceMaps"].AsBool = false;

            // Create Default Node
            SimpleJSON.JSONNode defaultNode = new SimpleJSON.JSONClass();
            defaultNode ["version"]             = "0.1.0";
            defaultNode ["configurations"] [-1] = defaultClass;

            if (!Directory.Exists(VSCode.LaunchFolder))
            {
                System.IO.Directory.CreateDirectory(VSCode.LaunchFolder);
            }

            if (!File.Exists(VSCode.LaunchPath))
            {
                File.WriteAllText(VSCode.LaunchPath, defaultNode.ToString());
            }
            else
            {
                string rawContent = File.ReadAllText(VSCode.LaunchPath);
                SimpleJSON.JSONNode existingNode = SimpleJSON.JSON.Parse(rawContent);

                bool found = false;

                if (existingNode != null && existingNode ["configurations"] != null)
                {
                    int index = 0;

                    foreach (SimpleJSON.JSONNode conf in existingNode["configurations"].AsArray)
                    {
                        if (conf ["name"].Value == "Unity")
                        {
                            found = true;
                            break;
                        }
                        index++;
                    }

                    if (found)
                    {
                        existingNode ["configurations"] [index] = defaultClass;
                    }
                }

                if (found)
                {
                    File.WriteAllText(VSCode.LaunchPath, existingNode.ToString());
                }
                else
                {
                    File.WriteAllText(VSCode.LaunchPath, defaultNode.ToString());
                }
            }
        }