Exemplo n.º 1
0
        /// <summary>
        ///   Writes the file represented by the given byte array to the given path.
        /// </summary>
        /// <remarks>
        ///   This method writes the given data as a file at the given path, if it is owned
        ///   by the fomod being upgraded. If the specified data file is not owned by the fomod
        ///   being upgraded, the file is instead written to the overwrites directory.
        ///   If the file was not previously installed by the fomod, then the normal install rules apply,
        ///   including confirming overwrite if applicable.
        /// </remarks>
        /// <param name="p_strPath">The path where the file is to be created.</param>
        /// <param name="p_bteData">The data that is to make up the file.</param>
        /// <returns>
        ///   <lang langref="true" /> if the file was written; <lang langref="false" /> if the user chose
        ///   not to overwrite an existing file.
        /// </returns>
        /// <exception cref="IllegalFilePathException">
        ///   Thrown if <paramref name="p_strPath" /> is
        ///   not safe.
        /// </exception>
        public override bool GenerateDataFile(string p_strPath, byte[] p_bteData)
        {
            PermissionsManager.CurrentPermissions.Assert();
            FileManagement.AssertFilePathIsSafe(p_strPath);

            IList <string> lstInstallers = InstallLog.Current.GetInstallingMods(p_strPath);

            if (lstInstallers.Contains(Fomod.BaseName))
            {
                string strWritePath;
                if (!lstInstallers[lstInstallers.Count - 1].Equals(Fomod.BaseName))
                {
                    var strDirectory  = Path.GetDirectoryName(p_strPath);
                    var strBackupPath = Path.Combine(Program.GameMode.OverwriteDirectory, strDirectory);
                    var strOldModKey  = InstallLog.Current.GetModKey(Fomod.BaseName);
                    var strFile       = strOldModKey + "_" + Path.GetFileName(p_strPath);
                    strWritePath = Path.Combine(strBackupPath, strFile);
                }
                else
                {
                    strWritePath = Path.Combine(Program.GameMode.PluginsPath, p_strPath);
                }
                Installer.TransactionalFileManager.WriteAllBytes(strWritePath, p_bteData);
                Installer.MergeModule.AddFile(p_strPath);
                return(true);
            }

            return(base.GenerateDataFile(p_strPath, p_bteData));
        }
Exemplo n.º 2
0
 /// <summary>
 ///   Retrieves the list of files in the specified BSA.
 /// </summary>
 /// <param name="p_strBsa">The BSA whose file listing is requested.</param>
 /// <returns>The list of files contained in the specified BSA.</returns>
 /// <exception cref="IllegalFilePathException">
 ///   Thrown if <paramref name="p_strBsa" />
 ///   contains illegal characters or refers to a file outside of the Data directory.
 /// </exception>
 /// <exception cref="BSAArchive.BSALoadException">Thrown if the specified BSA cannot be loaded.</exception>
 public string[] GetBSAFileList(string p_strBsa)
 {
     FileManagement.AssertFilePathIsSafe(p_strBsa);
     if (Path.GetDirectoryName(p_strBsa).Length > 0)
     {
         throw new IllegalFilePathException(p_strBsa);
     }
     PermissionsManager.CurrentPermissions.Assert();
     if (!m_dicBSAs.ContainsKey(p_strBsa))
     {
         m_dicBSAs[p_strBsa] = new BSAArchive(Path.Combine(Program.GameMode.PluginsPath, p_strBsa));
     }
     return((string[])m_dicBSAs[p_strBsa].FileNames.Clone());
 }
Exemplo n.º 3
0
        /// <summary>
        ///   Gets the specified file from the specified BSA.
        /// </summary>
        /// <param name="p_strBsa">The BSA from which to extract the specified file.</param>
        /// <param name="p_strFile">The files to extract form the specified BSA.</param>
        /// <returns>The data of the specified file.</returns>
        /// <exception cref="IllegalFilePathException">
        ///   Thrown if <paramref name="p_strBsa" />
        ///   contains illegal characters or refers to a file outside of the Data directory, or
        ///   if <paramref name="p_strFile" /> refers to an unsafe location.
        /// </exception>
        /// <exception cref="BSAArchive.BSALoadException">Thrown if the specified BSA cannot be loaded.</exception>
        public byte[] GetDataFileFromBSA(string p_strBsa, string p_strFile)
        {
            FileManagement.AssertFilePathIsSafe(p_strBsa);
            FileManagement.AssertFilePathIsSafe(p_strFile);
            if (Path.GetDirectoryName(p_strBsa).Length > 0)
            {
                throw new IllegalFilePathException(p_strBsa);
            }
            PermissionsManager.CurrentPermissions.Assert();
            var strLoweredBsa = p_strBsa.ToLowerInvariant();

            if (!m_dicBSAs.ContainsKey(strLoweredBsa))
            {
                m_dicBSAs[strLoweredBsa] = new BSAArchive(Path.Combine(Program.GameMode.PluginsPath, strLoweredBsa));
            }
            return(m_dicBSAs[strLoweredBsa].GetFile(p_strFile));
        }