Exemplo n.º 1
0
            public RootFolderInfo(Options opt, IEnumerable <string> paths = null)
                : base("", "", Guid.NewGuid())
            {
                GeneratedKeys = ReadKeyDatabase(opt.dbfilename);
                UserKeys      = ReadKeyDatabase(opt.userfilename);
                ComponentID   = opt.componentid;
                m_opt         = opt;

                string id;

                if (!GeneratedKeys.TryGetValue(DIR_SEP, out id))
                {
                    id = Guid.NewGuid().ToString();
                }

                if (UserKeys.ContainsKey(DIR_SEP))
                {
                    id = UserKeys[DIR_SEP];
                }

                this.ID = id;

                Add(paths);
            }
Exemplo n.º 2
0
            public void Add(string path)
            {
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                bool isDir = false;

                if (path.EndsWith(DIR_SEP))
                {
                    isDir = true;
                    path  = path.Substring(0, path.Length - 1);
                }

                List <string> folders  = new List <string>();
                string        filename = null;

                while (!string.IsNullOrEmpty(path))
                {
                    string sourcepath = System.IO.Path.GetDirectoryName(path);
                    string elname     = System.IO.Path.GetFileName(path);
                    folders.Add(elname);

                    path = sourcepath;
                    if (path.EndsWith(DIR_SEP))
                    {
                        path = path.Substring(0, path.Length - 1);
                    }
                }

                if (!isDir)
                {
                    filename = folders[0];
                    folders.RemoveAt(0);
                }

                IFolder cur = this;

                folders.Reverse();

                StringBuilder sbp = new StringBuilder();

                foreach (var f in folders)
                {
                    sbp.Append(f);
                    sbp.Append(DIR_SEP);

                    FolderInfo next;
                    if (!cur.Folders.TryGetValue(f, out next))
                    {
                        //We have a new folder
                        string id;
                        if (!GeneratedKeys.TryGetValue(sbp.ToString(), out id))
                        {
                            id = Guid.NewGuid().ToString();
                            GeneratedKeys.Add(sbp.ToString(), id);
                        }

                        Guid g;
                        try { g = new Guid(id); }
                        catch
                        {
                            g = Guid.NewGuid();
                            GeneratedKeys[sbp.ToString()] = g.ToString();
                            Console.Error.WriteLine("Unable to parse {0} into a GUID, I told you not to edit the file!!!{1}A new GUID will be used: {2}", id, Environment.NewLine, g);
                        }

                        string userkey;
                        if (!UserKeys.TryGetValue(sbp.ToString(), out userkey))
                        {
                            userkey = g.ToString();
                        }

                        next = new FolderInfo(f, userkey, g);
                        cur.Folders.Add(f, next);
                    }

                    cur = next;
                }

                if (!string.IsNullOrEmpty(filename))
                {
                    sbp.Append(filename);

                    string id;
                    if (!GeneratedKeys.TryGetValue(sbp.ToString(), out id))
                    {
                        GeneratedKeys.Add(sbp.ToString(), id = Guid.NewGuid().ToString());
                    }
                    if (UserKeys.ContainsKey(sbp.ToString()))
                    {
                        id = UserKeys[sbp.ToString()];
                    }

                    string fullpath = System.IO.Path.Combine(m_opt.fileprefix, sbp.ToString()).Replace(DIR_SEP, "\\");

                    cur.Files.Add(filename, new FileInfo(filename, id, fullpath));
                }
            }