Ejemplo n.º 1
0
 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);
             }
         }
     }
 }
        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);
            }
        }