Example #1
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;
        }
Example #2
0
        public EnableDisableItemsForm()
        {
            InitializeComponent();

            AssemblerSelectionBox.Items.AddRange(DataCache.Assemblers.Values.ToArray());
            AssemblerSelectionBox.Sorted        = true;
            AssemblerSelectionBox.DisplayMember = "FriendlyName";
            for (int i = 0; i < AssemblerSelectionBox.Items.Count; i++)
            {
                if (((Assembler)AssemblerSelectionBox.Items[i]).Enabled)
                {
                    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++)
            {
                if (((Miner)MinerSelectionBox.Items[i]).Enabled)
                {
                    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++)
            {
                if (((Module)ModuleSelectionBox.Items[i]).Enabled)
                {
                    ModuleSelectionBox.SetItemChecked(i, true);
                }
            }

            ModSelectionBox.Items.AddRange(DataCache.Mods.OrderBy <Mod, string>(m => m.Name).ToArray());
            ModSelectionBox.DisplayMember = "name";
            for (int i = 0; i < ModSelectionBox.Items.Count; i++)
            {
                Mod mod = (Mod)ModSelectionBox.Items[i];
                if (mod.Enabled)
                {
                    ModSelectionBox.SetItemChecked(i, true);
                }

                foreach (ModDependency dep in mod.parsedDependencies)
                {
                    if (dep.Optional)
                    {
                        continue;
                    }

                    Mod otherMod = this.getModFromName(dep.ModName);
                    if (otherMod == null)
                    {
                        ModSelectionBox.errors[i] = mod.Name + " requires " + dep.ModName + " but is missing";
                        break;
                    }
                    else if (!mod.DependsOn(otherMod, false))
                    {
                        ModSelectionBox.errors[i] = $"{mod.Name} requires {dep.ModName} {dep.VersionOperator.Token()} {dep.Version} but is {otherMod.version}";
                        break;
                    }
                }
            }

            ModsChanged = false;
        }