Ejemplo n.º 1
0
        /// <summary>
        /// Builds a mapping from Component keys to installation paths.
        /// </summary>
        /// <param name="db">Installation database.</param>
        /// <param name="directoryPathMap">Directory mapping returned by
        /// <see cref="BuildDirectoryPathMap(Database,bool)"/>.</param>
        /// <returns>An InstallPathMap with the described mapping.</returns>
        public static InstallPathMap BuildComponentPathMap(Database db, InstallPathMap directoryPathMap)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            InstallPathMap compPathMap = new InstallPathMap();

            using (View compView = db.OpenView("SELECT `Component`, `Directory_` FROM `Component`"))
            {
                compView.Execute();

                foreach (Record compRec in compView)
                {
                    using (compRec)
                    {
                        string      comp    = (string)compRec[1];
                        InstallPath dirPath = (InstallPath)directoryPathMap[(string)compRec[2]];

                        if (dirPath != null)
                        {
                            compPathMap[comp] = dirPath;
                        }
                    }
                }
            }

            return(compPathMap);
        }
Ejemplo n.º 2
0
        private static void LinkSubdirectories(string key, InstallPath dir, IDictionary dirTreeMap)
        {
            InstallPathMap subDirs = (InstallPathMap)dirTreeMap[key];

            if (subDirs != null)
            {
                foreach (KeyValuePair <string, InstallPath> entry in subDirs)
                {
                    string      subKey = (string)entry.Key;
                    InstallPath subDir = (InstallPath)entry.Value;
                    dir.ChildPaths.Add(subDir);
                    LinkSubdirectories(subKey, subDir, dirTreeMap);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a mapping from File keys to installation paths.
        /// </summary>
        /// <param name="db">Installation database.</param>
        /// <param name="componentPathMap">Component mapping returned by <see cref="BuildComponentPathMap"/>.</param>
        /// <param name="useShortNames">true to use short file names; false to use long names</param>
        /// <returns>An InstallPathMap with the described mapping.</returns>
        public static InstallPathMap BuildFilePathMap(Database db, InstallPathMap componentPathMap,
                                                      bool useShortNames)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            if (componentPathMap == null)
            {
                componentPathMap = BuildComponentPathMap(db, BuildDirectoryPathMap(db, useShortNames));
            }

            InstallPathMap filePathMap = new InstallPathMap();

            using (View fileView = db.OpenView("SELECT `File`, `Component_`, `FileName` FROM `File`"))
            {
                fileView.Execute();

                foreach (Record fileRec in fileView)
                {
                    using (fileRec)
                    {
                        string file     = (string)fileRec[1];
                        string comp     = (string)fileRec[2];
                        string fileName = (string)fileRec[3];

                        InstallPath compPath = (InstallPath)componentPathMap[comp];
                        if (compPath != null)
                        {
                            InstallPath filePath = new InstallPath(fileName, useShortNames);
                            compPath.ChildPaths.Add(filePath);
                            filePathMap[file] = filePath;
                        }
                    }
                }
            }

            return(filePathMap);
        }
Ejemplo n.º 4
0
 internal TargetPathMap(InstallPathMap map)
 {
     this.map = map;
 }
Ejemplo n.º 5
0
 internal SourcePathMap(InstallPathMap map)
 {
     this.map = map;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Builds a mapping of Directory keys to directory paths, specifying root directories
        /// for the source and target paths.
        /// </summary>
        /// <param name="db">Database containing the Directory table.</param>
        /// <param name="useShortNames">true to use short directory names; false to use long names</param>
        /// <param name="sourceRootDir">The root directory path of all source paths, or null to leave them relative.</param>
        /// <param name="targetRootDir">The root directory path of all source paths, or null to leave them relative.</param>
        /// <returns>An InstallPathMap with the described mapping.</returns>
        public static InstallPathMap BuildDirectoryPathMap(Database db, bool useShortNames,
                                                           string sourceRootDir, string targetRootDir)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            if (sourceRootDir == null)
            {
                sourceRootDir = "";
            }
            if (targetRootDir == null)
            {
                targetRootDir = "";
            }

            InstallPathMap dirMap     = new InstallPathMap();
            IDictionary    dirTreeMap = new Hashtable();

            using (View dirView = db.OpenView("SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`"))
            {
                dirView.Execute();

                foreach (Record dirRec in dirView)
                {
                    using (dirRec)
                    {
                        string      key       = (string)dirRec[1];
                        string      parentKey = (string)dirRec[2];
                        InstallPath dir       = new InstallPath((string)dirRec[3], useShortNames);

                        dirMap[key] = dir;

                        InstallPathMap siblingDirs = (InstallPathMap)dirTreeMap[parentKey];
                        if (siblingDirs == null)
                        {
                            siblingDirs           = new InstallPathMap();
                            dirTreeMap[parentKey] = siblingDirs;
                        }
                        siblingDirs.Add(key, dir);
                    }
                }
            }

            foreach (KeyValuePair <string, InstallPath> entry in (InstallPathMap)dirTreeMap[""])
            {
                string      key = (string)entry.Key;
                InstallPath dir = (InstallPath)entry.Value;
                LinkSubdirectories(key, dir, dirTreeMap);
            }

            InstallPath targetDirPath = (InstallPath)dirMap["TARGETDIR"];

            if (targetDirPath != null)
            {
                targetDirPath.SourcePath = sourceRootDir;
                targetDirPath.TargetPath = targetRootDir;
            }

            return(dirMap);
        }