예제 #1
0
        private void ModDirectoryButton_Click(object sender, EventArgs e)
        {
            using (DirectoryChooserForm form = new DirectoryChooserForm(Properties.Settings.Default.FactorioModPath))
            {
                form.Text = "Locate the mods directory";
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Properties.Settings.Default["FactorioModPath"] = form.SelectedPath;
                    Properties.Settings.Default.Save();

                    JObject savedGraph = JObject.Parse(JsonConvert.SerializeObject(GraphViewer));
                    ReloadFactorioData();
                    GraphViewer.LoadFromJson(savedGraph);
                    UpdateControlValues();
                }
            }
        }
예제 #2
0
		private void Form1_Load(object sender, EventArgs e)
		{
			String path = DataCache.FactorioDataPath;
			if (!Directory.Exists(path))
			{
				using (DirectoryChooserForm form = new DirectoryChooserForm())
				{
					if (form.ShowDialog() == DialogResult.OK)
					{
						path = form.SelectedPath;
						DataCache.AppDataModPath = Path.Combine(path, "mods");
						path = Path.Combine(path, "data");
					}
					else
					{
						Close();
						Dispose();
						return;
					}
				}
			}

			DataCache.FactorioDataPath = path;
			DataCache.LoadRecipes();
			if (DataCache.failedFiles.Any())
			{
				String errorMessage = "The following files could not be loaded due to errors:\n";
				foreach (String file in DataCache.failedFiles.Keys)
				{
					errorMessage += String.Format(file + "({0})\n", DataCache.failedFiles[file].Message);
				}
				Console.Error.WriteLine(errorMessage);
			}

			rateOptionsDropDown.SelectedIndex = 0;

			AssemblerSelectionBox.Items.Clear();
			AssemblerSelectionBox.Items.AddRange(DataCache.Assemblers.Values.ToArray());
			AssemblerSelectionBox.Sorted = true;
			AssemblerSelectionBox.DisplayMember = "FriendlyName";
			for ( int i = 0; i < AssemblerSelectionBox.Items.Count; i++)
			{
				AssemblerSelectionBox.SetItemChecked(i, true);
			}

			MinerSelectionBox.Items.AddRange(DataCache.Miners.Values.ToArray());
			MinerSelectionBox.Sorted = true;
			MinerSelectionBox.DisplayMember = "FriendlyName";
			for (int i = 0; i < MinerSelectionBox.Items.Count; i++)
			{
				MinerSelectionBox.SetItemChecked(i, true);
			}

			ModuleSelectionBox.Items.AddRange(DataCache.Modules.Values.ToArray());
			ModuleSelectionBox.Sorted = true;
			ModuleSelectionBox.DisplayMember = "FriendlyName";
			for (int i = 0; i < ModuleSelectionBox.Items.Count; i++)
			{
				ModuleSelectionBox.SetItemChecked(i, true);
			}

			ItemListBox.Items.Clear();
			ItemListBox.Items.AddRange(DataCache.Items.Values.ToArray());
			ItemListBox.DisplayMember = "FriendlyName";
			ItemListBox.Sorted = true;
		}
예제 #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //I changed the name of the variable, so this copies the value over for people who are upgrading their Foreman version
            if (Properties.Settings.Default.FactorioPath == "" && Properties.Settings.Default.FactorioDataPath != "")
            {
                Properties.Settings.Default["FactorioPath"]     = Path.GetDirectoryName(Properties.Settings.Default.FactorioDataPath);
                Properties.Settings.Default["FactorioDataPath"] = "";
            }

            if (!Directory.Exists(Properties.Settings.Default.FactorioPath))
            {
                List <FoundInstallation> installations = new List <FoundInstallation>();
                String steamFolder = Path.Combine("Steam", "steamapps", "common");
                foreach (String defaultPath in new String[] {
                    Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"), steamFolder, "Factorio"),
                    Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), steamFolder, "Factorio"),
                    Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"), "Factorio"),
                    Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Factorio"),
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Applications", "factorio.app", "Contents")
                })                                                                                                                          //Not actually tested on a Mac
                {
                    if (Directory.Exists(defaultPath))
                    {
                        FoundInstallation inst = FoundInstallation.GetInstallationFromPath(defaultPath);
                        if (inst != null)
                        {
                            installations.Add(inst);
                        }
                    }
                }

                if (installations.Count > 0)
                {
                    if (installations.Count > 1)
                    {
                        using (InstallationChooserForm form = new InstallationChooserForm(installations))
                        {
                            if (form.ShowDialog() == DialogResult.OK && form.SelectedPath != null)
                            {
                                Properties.Settings.Default["FactorioPath"] = form.SelectedPath;
                            }
                            else
                            {
                                Close();
                                Dispose();
                                return;
                            }
                        }
                    }
                    else
                    {
                        Properties.Settings.Default["FactorioPath"] = installations[0].path;
                    }

                    Properties.Settings.Default.Save();
                }
            }

            if (!Directory.Exists(Properties.Settings.Default.FactorioPath))
            {
                using (DirectoryChooserForm form = new DirectoryChooserForm(""))
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        Properties.Settings.Default["FactorioPath"] = form.SelectedPath;
                        Properties.Settings.Default.Save();
                    }
                    else
                    {
                        Close();
                        Dispose();
                        return;
                    }
                }
            }

            if (!Directory.Exists(Properties.Settings.Default.FactorioModPath))
            {
                if (Directory.Exists(Path.Combine(Properties.Settings.Default.FactorioPath, "mods")))
                {
                    Properties.Settings.Default["FactorioModPath"] = Path.Combine(Properties.Settings.Default.FactorioPath, "mods");
                }
                else if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "factorio", "mods")))
                {
                    Properties.Settings.Default["FactorioModPath"] = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "factorio", "mods");
                }
            }

            if (Properties.Settings.Default.EnabledMods == null)
            {
                Properties.Settings.Default.EnabledMods = new StringCollection();
            }
            if (Properties.Settings.Default.EnabledAssemblers == null)
            {
                Properties.Settings.Default.EnabledAssemblers = new StringCollection();
            }
            if (Properties.Settings.Default.EnabledMiners == null)
            {
                Properties.Settings.Default.EnabledMiners = new StringCollection();
            }
            if (Properties.Settings.Default.EnabledModules == null)
            {
                Properties.Settings.Default.EnabledModules = new StringCollection();
            }

            switch (Properties.Settings.Default.FactorioDifficulty)
            {
            case "normal":
                DataCache.Difficulty = "normal";
                NormalDifficultyRadioButton.Checked = true;
                break;

            case "expensive":
                DataCache.Difficulty = "expensive";
                ExpensiveDifficultyRadioButton.Checked = true;
                break;

            default:
                Properties.Settings.Default.FactorioDifficulty = "normal";
                Properties.Settings.Default.Save();
                DataCache.Difficulty = "normal";
                NormalDifficultyRadioButton.Checked = true;
                break;
            }

            ReloadFactorioData();

            // Register after loading settings to prevent an unnessecary data reload.
            NormalDifficultyRadioButton.CheckedChanged    += DifficultyChanged;
            ExpensiveDifficultyRadioButton.CheckedChanged += DifficultyChanged;

            LanguageDropDown.Items.AddRange(DataCache.Languages.ToArray());
            LanguageDropDown.SelectedItem = DataCache.Languages.FirstOrDefault(l => l.Name == Properties.Settings.Default.Language);

            UpdateControlValues();
        }
예제 #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string[] factorioPaths = new string[]
            {
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Factorio"),
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Factorio"),
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Factorio"),
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "factorio"),
            };

            String factorioPath = null;

            foreach (string testPath in factorioPaths)
            {
                if (File.Exists(Path.Combine(testPath, "data", "core", "lualib", "dataloader.lua")))
                {
                    Console.Out.WriteLine("Found factorio: " + testPath);
                    factorioPath = testPath;
                    break;
                }
            }

            if (factorioPath == null)
            {
                using (DirectoryChooserForm form = new DirectoryChooserForm())
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        factorioPath = form.SelectedPath;
                    }
                    else
                    {
                        Close();
                        Dispose();
                        return;
                    }
                }
            }

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

            string[] modPaths = new string[]
            {
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Factorio", "mods"),
                Path.Combine(factorioPath, "mods"),
            };
            foreach (string modPath in modPaths)
            {
                if (Directory.Exists(modPath))
                {
                    foreach (string mod in Directory.GetFiles(modPath, "*.zip", SearchOption.TopDirectoryOnly))
                    {
                        string modDirectory = UnzipMod(mod);
                        Console.Out.WriteLine("unpacking " + mod + " to temporary location " + modDirectory);

                        if (File.Exists(Path.Combine(modDirectory, "data.lua")))
                        {
                            mods.Add(modDirectory);
                            Console.Out.WriteLine("added mod directory " + modDirectory);
                        }
                    }

                    foreach (string modDirectory in Directory.GetDirectories(modPath, "*", SearchOption.TopDirectoryOnly))
                    {
                        if (File.Exists(Path.Combine(modDirectory, "data.lua")))
                        {
                            mods.Add(modDirectory);
                            Console.Out.WriteLine("added mod directory " + modDirectory);
                        }
                    }
                }
            }

            DataCache.LoadRecipes(factorioPath, mods);

            rateOptionsDropDown.SelectedIndex = 0;

            AssemblerSelectionBox.Items.Clear();
            AssemblerSelectionBox.Items.AddRange(DataCache.Assemblers.Values.ToArray());
            AssemblerSelectionBox.Sorted        = true;
            AssemblerSelectionBox.DisplayMember = "FriendlyName";
            for (int i = 0; i < AssemblerSelectionBox.Items.Count; i++)
            {
                AssemblerSelectionBox.SetItemChecked(i, true);
            }

            MinerSelectionBox.Items.AddRange(DataCache.Miners.Values.ToArray());
            MinerSelectionBox.Sorted        = true;
            MinerSelectionBox.DisplayMember = "FriendlyName";
            for (int i = 0; i < MinerSelectionBox.Items.Count; i++)
            {
                MinerSelectionBox.SetItemChecked(i, true);
            }

            ModuleSelectionBox.Items.AddRange(DataCache.Modules.Values.ToArray());
            ModuleSelectionBox.Sorted        = true;
            ModuleSelectionBox.DisplayMember = "FriendlyName";
            for (int i = 0; i < ModuleSelectionBox.Items.Count; i++)
            {
                ModuleSelectionBox.SetItemChecked(i, true);
            }

            ItemListBox.Items.Clear();
            ItemListBox.Items.AddRange(DataCache.Items.Values.ToArray());
            ItemListBox.DisplayMember = "FriendlyName";
            ItemListBox.Sorted        = true;
        }