Exemplo n.º 1
0
        /// <summary>
        /// The PFP edit constructor.
        /// </summary>
        /// <param name="p_pfpPack">The PFP to edit.</param>
        /// <param name="p_strSourcesPath">The path to the directory contains the required source files.</param>
        public FomodBuilderForm(PremadeFomodPack p_pfpPack, string p_strSourcesPath)
            : this()
        {
            List<KeyValuePair<string, string>> lstCopyInstructions = p_pfpPack.GetCopyInstructions(p_strSourcesPath);
            string strPremadeSource = Archive.GenerateArchivePath(p_pfpPack.PFPPath, p_pfpPack.PremadePath);
            lstCopyInstructions.Add(new KeyValuePair<string, string>(strPremadeSource, "/"));

            List<SourceFile> lstSourceFiles = p_pfpPack.GetSources();
            lstSourceFiles.ForEach((s) => { s.Source = Path.Combine(p_strSourcesPath, s.Source); });
            lstSourceFiles.Add(new SourceFile(p_pfpPack.PFPPath, null, true, false, false));

            ffsFileStructure.SetCopyInstructions(lstSourceFiles, lstCopyInstructions);
            tbxFomodFileName.Text = p_pfpPack.FomodName;
            sdsDownloadLocations.DataSource = lstSourceFiles;
            cbxPFP.Checked = true;
            tbxPFPPath.Text = Path.GetDirectoryName(p_pfpPack.PFPPath);
            tbxHowTo.Text = p_pfpPack.GetCustomHowToSteps();
        }
Exemplo n.º 2
0
        /// <summary>
        ///   The PFP edit constructor.
        /// </summary>
        /// <param name="p_pfpPack">The PFP to edit.</param>
        /// <param name="p_strSourcesPath">The path to the directory contains the required source files.</param>
        public FomodBuilderForm(PremadeFomodPack p_pfpPack, string p_strSourcesPath)
            : this()
        {
            var lstCopyInstructions = p_pfpPack.GetCopyInstructions(p_strSourcesPath);
            var strPremadeSource    = Archive.GenerateArchivePath(p_pfpPack.PFPPath, p_pfpPack.PremadePath);

            lstCopyInstructions.Add(new KeyValuePair <string, string>(strPremadeSource, "/"));

            var lstSourceFiles = p_pfpPack.GetSources();

            lstSourceFiles.ForEach(s =>
            {
                s.Source = Path.Combine(p_strSourcesPath, s.Source);
            });
            lstSourceFiles.Add(new SourceFile(p_pfpPack.PFPPath, null, true, false, false));

            ffsFileStructure.SetCopyInstructions(lstSourceFiles, lstCopyInstructions);
            tbxFomodFileName.Text           = p_pfpPack.FomodName;
            sdsDownloadLocations.DataSource = lstSourceFiles;
            cbxPFP.Checked  = true;
            tbxPFPPath.Text = Path.GetDirectoryName(p_pfpPack.PFPPath);
            tbxHowTo.Text   = p_pfpPack.GetCustomHowToSteps();
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Validates the selected paths.
        /// </summary>
        /// <remarks>
        ///   This makes sure the selected PFP file is a valid PFP, and that all required sources are present.
        /// </remarks>
        /// <returns><lang langref="true" /> if the selected paths are valid; <lang langref="false" /> otherwise.</returns>
        protected bool ValidateFiles()
        {
            erpError.Clear();
            if (String.IsNullOrEmpty(tbxPFP.Text))
            {
                erpError.SetError(butPFP, "You must specify a PFP.");
                return(false);
            }
            if (!File.Exists(tbxPFP.Text))
            {
                erpError.SetError(butPFP, "File does not exist.");
                return(false);
            }

            var strError = PremadeFomodPack.ValidatePFP(tbxPFP.Text);

            if (!String.IsNullOrEmpty(strError))
            {
                erpError.SetError(butPFP, "File is not a valid PFP: " + strError);
                return(false);
            }
            var pfpPack    = new PremadeFomodPack(tbxPFP.Text);
            var lstSources = pfpPack.GetSources();

            if (lstSources.Count > 0)
            {
                if (String.IsNullOrEmpty(tbxSources.Text))
                {
                    erpError.SetError(butSources, "You must specify a folder containing the required source files.");
                    return(false);
                }
                if (!Directory.Exists(tbxSources.Text))
                {
                    erpError.SetError(butSources, "Folder does not exist.");
                    return(false);
                }
                var lstMissingSources       = new List <SourceFile>();
                var lstMissingHiddenSources = new List <SourceFile>();
                foreach (var sflSource in lstSources)
                {
                    var booSourceMissing = !File.Exists(Path.Combine(tbxSources.Text, sflSource.Source)) &&
                                           !Directory.Exists(Path.Combine(tbxSources.Text, sflSource.Source));
                    if ((!sflSource.Hidden || sflSource.Generated) && booSourceMissing)
                    {
                        lstMissingSources.Add(sflSource);
                    }
                    if ((sflSource.Hidden && !sflSource.Generated) && booSourceMissing)
                    {
                        lstMissingHiddenSources.Add(sflSource);
                    }
                }
                if ((lstMissingSources.Count > 0) || ((m_omdMode == OpenPFPMode.Edit) && (lstMissingHiddenSources.Count > 0)))
                {
                    erpError.SetError(butSources, "Missing sources.");

                    var stbErrorHtml = new StringBuilder("<html><body bgcolor=\"");
                    stbErrorHtml.AppendFormat("#{0:x6}", Color.FromKnownColor(KnownColor.Control).ToArgb() & 0x00ffffff);
                    stbErrorHtml.Append("\">");
                    var booMissingGeneratedFiles = false;
                    if (lstMissingSources.Count > 0)
                    {
                        stbErrorHtml.Append("The following sources are missing:<ul>");
                        foreach (var sflSource in lstMissingSources)
                        {
                            if (!sflSource.Generated)
                            {
                                stbErrorHtml.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", sflSource.URL, sflSource.SourceFileName)
                                .AppendLine();
                            }
                            else
                            {
                                booMissingGeneratedFiles = true;
                                stbErrorHtml.AppendFormat("<li>{0}</li>", sflSource.SourceFileName).AppendLine();
                            }
                        }
                        stbErrorHtml.AppendLine("</ul>");
                    }
                    if (lstMissingHiddenSources.Count > 0)
                    {
                        stbErrorHtml.Append("Some of the missing sources require the following files to be downloaded:<ul>");
                        foreach (var sflSource in lstMissingHiddenSources)
                        {
                            stbErrorHtml.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", sflSource.URL, sflSource.SourceFileName)
                            .AppendLine();
                        }
                        stbErrorHtml.AppendLine("</ul>");
                    }
                    if (booMissingGeneratedFiles)
                    {
                        stbErrorHtml.Append(
                            "You are missing some files that need to be created before FOMM can open the Premade FOMod Pack (PFP). ");
                        stbErrorHtml.Append("Please read the <b>howto.txt</b> file included in the PFP.");
                    }

                    stbErrorHtml.Append("</body></html>");
                    ShowHTML(stbErrorHtml.ToString());
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates the selected paths.
        /// </summary>
        /// <remarks>
        /// This makes sure the selected PFP file is a valid PFP, and that all required sources are present.
        /// </remarks>
        /// <returns><lang cref="true"/> if the selected paths are valid; <lang cref="false"/> otherwise.</returns>
        protected bool ValidateFiles()
        {
            erpError.Clear();
            if (String.IsNullOrEmpty(tbxPFP.Text))
            {
                erpError.SetError(butPFP, "You must specify a PFP.");
                return false;
            }
            if (!File.Exists(tbxPFP.Text))
            {
                erpError.SetError(butPFP, "File does not exist.");
                return false;
            }

            string strError = PremadeFomodPack.ValidatePFP(tbxPFP.Text);
            if (!String.IsNullOrEmpty(strError))
            {
                erpError.SetError(butPFP, "File is not a valid PFP: " + strError);
                return false;
            }
            PremadeFomodPack pfpPack = new PremadeFomodPack(tbxPFP.Text);
            List<SourceFile> lstSources = pfpPack.GetSources();
            if (lstSources.Count > 0)
            {
                if (String.IsNullOrEmpty(tbxSources.Text))
                {
                    erpError.SetError(butSources, "You must specify a folder containing the required source files.");
                    return false;
                }
                if (!Directory.Exists(tbxSources.Text))
                {
                    erpError.SetError(butSources, "Folder does not exist.");
                    return false;
                }
                List<SourceFile> lstMissingSources = new List<SourceFile>();
                List<SourceFile> lstMissingHiddenSources = new List<SourceFile>();
                bool booSourceMissing = false;
                foreach (SourceFile sflSource in lstSources)
                {
                    booSourceMissing = !File.Exists(Path.Combine(tbxSources.Text, sflSource.Source)) && !Directory.Exists(Path.Combine(tbxSources.Text, sflSource.Source));
                    if ((!sflSource.Hidden || sflSource.Generated) && booSourceMissing)
                        lstMissingSources.Add(sflSource);
                    if ((sflSource.Hidden && !sflSource.Generated) && booSourceMissing)
                        lstMissingHiddenSources.Add(sflSource);
                }
                if ((lstMissingSources.Count > 0) || ((m_omdMode == OpenPFPMode.Edit) && (lstMissingHiddenSources.Count > 0)))
                {
                    erpError.SetError(butSources, "Missing sources.");

                    StringBuilder stbErrorHtml = new StringBuilder("<html><body bgcolor=\"");
                    stbErrorHtml.AppendFormat("#{0:x6}", Color.FromKnownColor(KnownColor.Control).ToArgb() & 0x00ffffff);
                    stbErrorHtml.Append("\">");
                    bool booMissingGeneratedFiles = false;
                    if (lstMissingSources.Count > 0)
                    {
                        stbErrorHtml.Append("The following sources are missing:<ul>");
                        foreach (SourceFile sflSource in lstMissingSources)
                        {
                            if (!sflSource.Generated)
                                stbErrorHtml.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", sflSource.URL, sflSource.SourceFileName).AppendLine();
                            else
                            {
                                booMissingGeneratedFiles = true;
                                stbErrorHtml.AppendFormat("<li>{0}</li>", sflSource.SourceFileName).AppendLine();
                            }
                        }
                        stbErrorHtml.AppendLine("</ul>");
                    }
                    if (lstMissingHiddenSources.Count > 0)
                    {
                        stbErrorHtml.Append("Some of the missing sources require the following files to be downloaded:<ul>");
                        foreach (SourceFile sflSource in lstMissingHiddenSources)
                            stbErrorHtml.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", sflSource.URL, sflSource.SourceFileName).AppendLine();
                        stbErrorHtml.AppendLine("</ul>");
                    }
                    if (booMissingGeneratedFiles)
                    {
                        stbErrorHtml.Append("You are missing some files that need to be created before FOMM can open the Premade FOMod Pack (PFP). ");
                        stbErrorHtml.Append("Please read the <b>howto.txt</b> file included in the PFP.");
                    }

                    stbErrorHtml.Append("</body></html>");
                    ShowHTML(stbErrorHtml.ToString());
                    return false;
                }
            }

            return true;
        }