private void modinfo_Closing(object sender, CancelEventArgs e)
 {
     foreach (Mcmod mcmod in _mods)
     {
         if (mcmod.IsSkipping)
             continue;
         if (String.IsNullOrWhiteSpace(mcmod.Name))
         {
             e.Cancel = true;
             MessageBox.Show("Please check all mods and make sure the info is filled in." +
                             Environment.NewLine + "Issue with mod: " + mcmod.Filename);
             return;
         }
         if (String.IsNullOrWhiteSpace(mcmod.Modid))
         {
             mcmod.Modid = mcmod.Name.Replace(" ", "").ToLower();
         }
         if (!AreModDone(mcmod))
         {
             e.Cancel = true;
             MessageBox.Show("Please check all mods and make sure the info is filled in." +
                             Environment.NewLine + "Issue with mod: " + mcmod.Filename);
             return;
         }
         mcmod.Aredone = true;
     }
     if (!e.Cancel)
     {
         foreach (Mcmod mcmod in _mods)
         {
             if (mcmod.FromUserInput && !mcmod.FromSuggestion)
             {
                 Debug.WriteLine(mcmod.Modid);
                 DataSuggest ds = new DataSuggest();
                 String a = _solderHelper.GetAuthors(mcmod, true);
                 ds.Suggest(mcmod.Filename, mcmod.Mcversion, mcmod.Version,
                     SqlHelper.CalculateMd5(mcmod.Path), mcmod.Modid, mcmod.Name, a);
             }
             if (_solderHelper.CreateFTBPack.Checked)
             {
                 _solderHelper.CreateFtbPackZip(mcmod, mcmod.Path);
             }
             if (_solderHelper.CreateTechnicPack.Checked)
             {
                 _solderHelper.CreateTechnicModZip(mcmod, mcmod.Path);
             }
         }
     }
 }
        public Modinfo(List<Mcmod> modsList, SolderHelper solderHelper)
        {
            _nonFinishedMods = new List<Mcmod>();
            _solderHelper = solderHelper;
            var tmp = from mcmod1 in modsList
                      where mcmod1.Name != null
                      orderby mcmod1.Name
                      select mcmod1;
            _mods = new List<Mcmod>();
            _mods.AddRange(tmp.ToList());
            tmp = from mcmod1 in modsList
                  where mcmod1.Name == null
                  orderby mcmod1.Filename
                  select mcmod1;
            _mods.AddRange(tmp.ToList());
            InitializeComponent();
            foreach (Mcmod mcmod in _mods)
            {
                if (String.IsNullOrWhiteSpace(mcmod.Mcversion))
                    mcmod.Mcversion = solderHelper._currentMcVersion;
                mcmod.Aredone = AreModDone(mcmod);
                if (!mcmod.Aredone)
                {
                    ModListSqlHelper modListSqlHelper = new ModListSqlHelper();
                    Mcmod m = modListSqlHelper.GetModInfo(SqlHelper.CalculateMd5(mcmod.Path));
                    if (m == null)
                    {
                        if (mcmod.Authors == null || mcmod.AuthorList == null)
                        {
                            String a = _solderHelper.GetAuthors(mcmod, true);
                            if (!String.IsNullOrWhiteSpace(a))
                            {
                                List<String> s = a.Replace(" ", "").Split(',').ToList();
                                mcmod.Authors = s;
                            }
                        }
                        if (!IsValid(mcmod.Mcversion))
                        {
                            mcmod.Mcversion = _solderHelper._currentMcVersion;
                        }
                        if (AreModDone(mcmod))
                        {
                            mcmod.Aredone = true;
                        }
                        else
                        {
                            DataSuggest ds = new DataSuggest();
                            m = ds.GetMcmod(SqlHelper.CalculateMd5(mcmod.Path));
                            if (m != null)
                            {
                                if (!IsValid(mcmod.Name))
                                {
                                    mcmod.Name = m.Name;
                                }
                                if (!IsValid(mcmod.Modid))
                                {
                                    mcmod.Modid = m.Modid;
                                }
                                if (!IsValid(mcmod.Version))
                                {
                                    mcmod.Version = m.Version;
                                }
                                mcmod.FromSuggestion = true;
                            }
                            if (AreModDone(mcmod))
                            {
                                mcmod.Aredone = true;
                            }
                            else
                            {
                                _nonFinishedMods.Add(mcmod);
                                modlist.Items.Add(String.IsNullOrWhiteSpace(mcmod.Name) ? mcmod.Filename : mcmod.Name);
                            }
                        }
                    }
                    if (!mcmod.Aredone)
                    {

                        if (m != null)
                        {
                            if (!IsValid(mcmod.Name) &&
                                !String.IsNullOrWhiteSpace(m.Name))
                            {
                                mcmod.Name = m.Name;
                            }
                            if (!IsValid(mcmod.Modid) && !String.IsNullOrWhiteSpace(m.Modid))
                            {
                                mcmod.Modid = m.Modid;
                            }
                            if (!IsValid(mcmod.Version) && !String.IsNullOrWhiteSpace(m.Version))
                            {
                                mcmod.Version = m.Version;
                            }
                        }
                        if (!IsValid(mcmod.Mcversion))
                        {
                            mcmod.Mcversion = _solderHelper._currentMcVersion;
                        }
                        if (mcmod.Authors == null || mcmod.AuthorList == null)
                        {
                            String a = _solderHelper.GetAuthors(mcmod, true);
                            if (a != null)
                            {
                                List<String> s = a.Replace(" ", "").Split(',').ToList();
                                mcmod.Authors = s;
                            }
                        }
                        if (AreModDone(mcmod))
                        {
                            mcmod.Aredone = true;
                        }
                        else
                        {
                            DataSuggest ds = new DataSuggest();
                            m = ds.GetMcmod(SqlHelper.CalculateMd5(mcmod.Path));
                            if (m != null)
                            {
                                if (!IsValid(mcmod.Name))
                                {
                                    mcmod.Name = m.Name;
                                }
                                if (!IsValid(mcmod.Modid))
                                {
                                    mcmod.Modid = m.Modid;
                                }
                                if (!IsValid(mcmod.Version))
                                {
                                    mcmod.Version = m.Version;
                                }
                                mcmod.FromSuggestion = true;
                            }
                            if (AreModDone(mcmod))
                            {
                                mcmod.Aredone = true;
                            }
                            else
                            {
                                if (!_nonFinishedMods.Contains(mcmod))
                                {
                                    _nonFinishedMods.Add(mcmod);
                                    modlist.Items.Add(String.IsNullOrWhiteSpace(mcmod.Name) ? mcmod.Filename : mcmod.Name);
                                }
                            }
                        }
                    }
                }
            }
            if (modlist.Items.Count <= 0)
            {
            }
            else
            {
                modlist.SelectedIndex = 0;
            }
        }
        private void RequireUserInfo(Mcmod currentData, String file)
        {
            try
            {
                Mcmod mod;
                String s = SqlHelper.CalculateMd5(file);
                Debug.WriteLine(s);
                DataSuggest suggest = new DataSuggest();

                try
                {
                    mod = _modsSqLhelper.GetModInfo(s);
                    Debug.WriteLine("Got from local database");
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    mod = suggest.GetMcmod(s);
                    if (mod == null)
                    {
                        mod = new Mcmod();
                    }
                    else
                    {
                        mod.FromSuggestion = true;
                        Debug.WriteLine("Got from remove database");
                    }
                }
                if (mod == null)
                {
                    Debug.WriteLine("didn't get anything from local database");
                    mod = suggest.GetMcmod(SqlHelper.CalculateMd5(file));
                    if (mod == null)
                    {
                        mod = new Mcmod();
                    }
                    else
                    {
                        mod.FromSuggestion = true;
                        Debug.WriteLine("Got from remove database");
                    }
                }

                String fileName = file.Substring(file.LastIndexOf(Globalfunctions.PathSeperator) + 1);
                fileName = fileName.Remove(fileName.LastIndexOf(".", StringComparison.Ordinal));

                if (currentData.Name != null && !currentData.Name.Contains("${") && !currentData.Name.ToLower().Contains("example"))
                {
                    mod.Name = currentData.Name;

                }
                else
                {
                    if (mod.Name == null && (String.IsNullOrWhiteSpace(currentData.Name) || currentData.Name.Contains("${") || currentData.Name.ToLower().Contains("example")))
                    {
                        String a =
                            string.Format("Mod name of {0}{1}Go bug the mod author to include an mcmod.info file!",
                                fileName, Environment.NewLine);
                        mod.Name = Prompt.ShowDialog(a, "Mod Name", false,
                            Prompt.ModsLeftString(_totalMods, _currentMod));
                        currentData.Name = mod.Name;
                        if (mod.Name.Equals(""))
                            return;
                        mod.FromUserInput = true;
                    }

                }
                if (currentData.Version != null && !currentData.Version.Contains("${") && !currentData.Version.ToLower().Contains("@version@") && !currentData.Version.ToLower().Contains("example"))
                    mod.Version = currentData.Version.Replace(" ", "-").ToLower();
                else
                {
                    if (mod.Version == null && (String.IsNullOrWhiteSpace(currentData.Version) || currentData.Version.Contains("${") || currentData.Version.ToLower().Contains("@version@") || currentData.Version.ToLower().Contains("example")))
                    {
                        String a =
                            String.Format(
                                "Mod version of {0}" + Environment.NewLine +
                                "Go bug the mod author to include an mcmod.info file!", fileName);
                        mod.Version = Prompt.ShowDialog(a, "Mod Version", false,
                            Prompt.ModsLeftString(_totalMods, _currentMod));
                        mod.Version = mod.Version.Replace(" ", "-").ToLower();
                        if (mod.Version.Equals(""))
                            return;
                        mod.FromUserInput = true;
                    }
                }
                if (mod.Version != null)
                {
                    mod.Version = mod.Version.Replace(" ", "-");
                }

                if (currentData.Mcversion != null && !currentData.Mcversion.Contains("${") && !currentData.Mcversion.ToLower().Contains("example"))
                    mod.Mcversion = currentData.Mcversion;
                else if (mod.Mcversion == null && (String.IsNullOrWhiteSpace(currentData.Mcversion) || currentData.Mcversion.Contains("${") || currentData.Mcversion.ToLower().Contains("example")))
                    if (_currentMcVersion == null)
                    {
                        Mcselector selector = new Mcselector(this);
                        selector.ShowDialog();
                        currentData.Mcversion = _currentMcVersion;
                    }
                    else
                    {
                        mod.Mcversion = _currentMcVersion;
                        currentData.Mcversion = _currentMcVersion;
                    }

                if (!String.IsNullOrWhiteSpace(currentData.Modid) && !currentData.Modid.ToLower().Contains("example") && !currentData.Modid.Contains("${"))
                {
                    mod.Modid = currentData.Modid;
                }
                //mod.Modid = currentData.Modid ?? mod.Name.Replace(" ", "").ToLower();
                if (mod.Name != null && (String.IsNullOrWhiteSpace(mod.Modid) || mod.Modid.Contains("${") || mod.Modid.ToLower().Contains("example")))
                {
                    mod.Modid = mod.Name.ToLower();
                }
                mod.Modid = mod.Name.Replace(" ", "");

                string md5 = SqlHelper.CalculateMd5(file);
                if (mod.FromUserInput && !mod.FromSuggestion && !suggest.IsModSuggested(md5))
                {
                    String a = GetAuthors(mod);
                    suggest.Suggest(fileName, mod.Mcversion, mod.Version, md5, mod.Modid, mod.Name, a);
                }

                if (CreateTechnicPack.Checked)
                    CreateTechnicModZip(mod, file);
                if (CreateFTBPack.Checked)
                    CreateFtbPackZip(mod, file);
            }
            catch (NullReferenceException ex)
            {
                String error = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "error.txt");
                File.AppendAllText(error, ex.Message);
                File.AppendAllText(error, ex.StackTrace);
                MessageBox.Show("Please check the error.txt file on your desktop, and send it to the developer.");
                RequireUserInfo(file);
            }
        }