public static void Main(string[] args)
    {
        Console.WriteLine("Running in: " + Directory.GetCurrentDirectory());
        try
        {
            var handle = GetConsoleWindow();
            ShowWindow(handle, SW_HIDE);
        }
        catch (Exception)
        {
        }

        for (int i = 0; i < args.Length; i++)
        {
            /*if (args[i] == "-s")
             * {
             *      //  If -s is found in the arguments check if the port is specified
             *      for (int j = 0; j < args.Length; j++)
             *      {
             *              if (args[j] == "-p" && j < args.Length - 1)
             *              {
             *                      //  If -p is found set port to the next argument
             *                      port = Convert.ToInt32(args[j+1]);
             *              }
             *      }
             *      //  Start server and return from Main() before client is started
             *      StartServer(port);
             *      return;
             * }*/
        }

        /*OpenFileDialog test = new OpenFileDialog();
         * test.Filter = ".ini|*.ini";
         * test.Title = "Test";
         * test.ShowDialog();*/

        try
        {
            //Test();
            ConvertFiles();
        }
        catch (Exception e)
        {
            Console.WriteLine("Conversion Error: " + e.Message + "\n" + e.StackTrace);
        }

        //try
        {
            config = new FileReader("config.ini", SortingStyle.Sort);
            config.AddNewItem("version", "");
            config.AddNewItem("file_index", "0");
            config.AddNewItem("casual_mode", "0");
            config.AddNewItem("layout", "1");
            config.AddNewItem("include_route_pbs_in_individuals_file", "0");
            config.AddNewItem("sums_horizontal_alignment", "0");

            List <string> fonts = new List <string>();

            foreach (FontFamily f in System.Drawing.FontFamily.Families)
            {
                fonts.Add(f.Name);
            }

            if (fonts.Contains("Segoe UI"))
            {
                config.AddNewItem("font", "Segoe UI");
            }
            else if (fonts.Contains("DejaVu Sans"))
            {
                config.AddNewItem("font", "DejaVu Sans");
            }
            else if (fonts.Contains("Arial"))
            {
                config.AddNewItem("font", "Arial");
            }
            else
            {
                config.AddNewItem("font", SystemFonts.MessageBoxFont.Name);
            }

            config.AddNewItem("font_size", "18");
            config.AddNewItem("highlight_current", "0");
            config.AddNewItem("start_highlighted", "1");
            config.AddNewItem("horizontal_width", "1296");
            config.AddNewItem("horizontal_height", "99");
            config.AddNewItem("vertical_width", "316");
            config.AddNewItem("vertical_height", "309");
            config["version"] = version;

            if (config.ContainsKey("debug") && config["debug"] == "1")
            {
                try
                {
                    var handle = GetConsoleWindow();
                    ShowWindow(handle, SW_SHOW);
                }
                catch (Exception)
                {
                }
            }

            if (config ["layout"] == "horizontal")
            {
                config ["layout"] = "0";
            }
            if (config ["layout"] == "vertical")
            {
                config ["layout"] = "1";
            }
            if (config ["layout"] != "0" && config ["layout"] != "1")
            {
                config ["layout"] = "0";
            }

            if (config ["sums_horizontal_alignment"] == "right")
            {
                config ["sums_horizontal_alignment"] = "0";
            }
            if (config ["sums_horizontal_alignment"] == "left")
            {
                config ["sums_horizontal_alignment"] = "1";
            }
            if (config ["sums_horizontal_alignment"] != "0" && config ["sums_horizontal_alignment"] != "1")
            {
                config ["sums_horizontal_alignment"] = "0";
            }

            config.Save();

            colors = new ColorFileReader("color_theme.ini", SortingStyle.Validate);
            colors.AddNewItem("text_color", "#FFFFFF");
            colors.AddNewItem("text_color_total", "#FFFFFF");
            colors.AddNewItem("text_color_highlighted", "#FFFFFF");
            colors.AddNewItem("background_color", "#0F0F0F");
            colors.AddNewItem("background_color_highlighted", "#3373F4");
            colors.AddNewItem("text_color_ahead", "#00CC36");
            colors.AddNewItem("text_color_behind", "#CC1200");
            colors.AddNewItem("text_color_best", "#D8AF1F");

            if (config.ContainsKey("text_color"))
            {
                string c = config["text_color"];
                config.RemoveKey("text_color");
                colors["text_color"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("text_color_total"))
            {
                string c = config["text_color_total"];
                config.RemoveKey("text_color_total");
                colors["text_color_total"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("text_color_highlighted"))
            {
                string c = config["text_color_highlighted"];
                config.RemoveKey("text_color_highlighted");
                colors["text_color_highlighted"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("background_color"))
            {
                string c = config["background_color"];
                config.RemoveKey("background_color");
                colors["background_color"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("background_color_highlighted"))
            {
                string c = config["background_color_highlighted"];
                config.RemoveKey("background_color_highlighted");
                colors["background_color_highlighted"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("text_color_ahead"))
            {
                string c = config["text_color_ahead"];
                config.RemoveKey("text_color_ahead");
                colors["text_color_ahead"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("text_color_behind"))
            {
                string c = config["text_color_behind"];
                config.RemoveKey("text_color_behind");
                colors["text_color_behind"] = ColorTranslator.FromHtml(c);
            }
            if (config.ContainsKey("text_color_best"))
            {
                string c = config["text_color_best"];
                config.RemoveKey("text_color_best");
                colors["text_color_best"] = ColorTranslator.FromHtml(c);
            }

            files = new List <string>();
            if (config.ContainsSection("Files"))
            {
                foreach (string key in config.GetSection("Files").Keys)
                {
                    if (!System.IO.File.Exists(config["Files", key]))
                    {
                        config.RemoveKey("Files", key);
                        continue;
                    }
                    try
                    {
                        FileReader tmp = new FileReader(config["Files", key]);

                        if (!tmp.ContainsSection("Best Run"))
                        {
                            config.RemoveKey("Files", key);
                            continue;
                        }
                    }
                    catch (Exception)
                    {
                        config.RemoveKey("Files", key);
                        continue;
                    }
                    files.Add(config["Files", key]);
                    config.RemoveKey("Files", key);
                }
                int fileIndex = 0;
                foreach (string file in files)
                {
                    config.AddNewItem("Files", "File_" + FormatNumber(fileIndex++), file);
                }
            }
            else
            {
                config["Files", "File_0000"] = "pb_easy.ini";
                config["Files", "File_0001"] = "pb_hard.ini";
                files.Add("pb_easy.ini");
                files.Add("pb_hard.ini");
            }

            colors.Save();
            config.Save();


            FileReader pbEasy = new FileReader("pb_easy.ini", SortingStyle.Validate);
            if (!File.Exists("pb_easy.ini"))
            {
                pbEasy.AddNewItem("Best Run", "Corneria", "0");
                pbEasy.AddNewItem("Best Run", "Meteo", "0");
                pbEasy.AddNewItem("Best Run", "Katina", "0");
                pbEasy.AddNewItem("Best Run", "Sector X", "0");
                pbEasy.AddNewItem("Best Run", "Macbeth", "0");
                pbEasy.AddNewItem("Best Run", "Area 6", "0");
                pbEasy.AddNewItem("Best Run", "Venom 2", "0");
                pbEasy.Save();
            }
            if (!pbEasy.ContainsKey("game"))
            {
                pbEasy["name"] = "Easy Route";
                pbEasy["game"] = "Star Fox 64";
                //pbEasy["IL Syncing"] = "on";
            }

            TrackerData.ValidateFile(pbEasy);

            FileReader pbHard = new FileReader("pb_hard.ini", SortingStyle.Validate);
            if (!File.Exists("pb_hard.ini"))
            {
                pbHard.AddNewItem("Best Run", "Corneria", "0");
                pbHard.AddNewItem("Best Run", "Sector Y", "0");
                pbHard.AddNewItem("Best Run", "Aquas", "0");
                pbHard.AddNewItem("Best Run", "Zoness", "0");
                pbHard.AddNewItem("Best Run", "Macbeth", "0");
                pbHard.AddNewItem("Best Run", "Area 6", "0");
                pbHard.AddNewItem("Best Run", "Venom 2", "0");
                pbHard.Save();
            }
            if (!pbHard.ContainsKey("game"))
            {
                pbHard["name"] = "Hard Route";
                pbHard["game"] = "Star Fox 64";
                //pbHard["IL Syncing"] = "on";
            }

            TrackerData.ValidateFile(pbHard);


            individualLevels = new FileReader(':', "pb_individuals.txt", SortingStyle.Unsort);

            fileIndex = Int32.Parse(config["file_index"]);
            if (fileIndex >= files.Count || fileIndex < 0)
            {
                fileIndex            = 0;
                config["file_index"] = "0";
                config.Save();
            }

            data    = new TrackerData(new FileReader(files[FileIndex], SortingStyle.Validate));
            tracker = new TrackerCore(data);
        }

        /*
         *          catch (Exception e)
         *          {
         *                  Console.WriteLine("Startup Error: " + e.Message);
         *          }
         */

        try
        {
            Application.Run(new InputWindow());
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine(e.StackTrace);
        }


        if (config.ContainsKey("debug") && config["debug"] == "1")
        {
            Console.Read();
        }
    }