예제 #1
0
        public static EfsEntry NewRoot()
        {
            EfsEntry res = NewFolder(0, "");

            res.idParent = null;
            return(res);
        }
예제 #2
0
        public static EfsEntry NewFolder(int idParent, string name)
        {
            EfsEntry res = NewFile(idParent, name);

            res.m_isDirectory = true;
            return(res);
        }
예제 #3
0
        public static EfsEntry NewFile(int idParent, FileInfo info)
        {
            var res = new EfsEntry();

            res.idParent = idParent;
            res.SetInfo(info);
            return(res);
        }
예제 #4
0
        public static EfsEntry NewFolder(int idParent, DirectoryInfo info)
        {
            var res = new EfsEntry();

            res.idParent      = idParent;
            res.m_isDirectory = true;
            res.SetInfo(info);
            return(res);
        }
예제 #5
0
        public static EfsEntry NewFile(int idParent, string name)
        {
            EfsEntry res = new EfsEntry();

            res.SetAllTimestamps();
            res.idParent = idParent;
            res.name     = name;
            return(res);
        }
예제 #6
0
        /// <summary>Create a new folder</summary>
        /// <param name="cur"></param>
        /// <param name="idParent">Parent folder ID</param>
        /// <param name="name">Folder name</param>
        /// <returns></returns>
        public static EfsEntry CreateFolder(Cursor <EfsEntry> cur, int idParent, string name)
        {
            if (name.IndexOfAny(s_PathSplitCharacters) >= 0)
            {
                throw new IOException("Invalid name");
            }
            var ne = EfsEntry.NewFolder(idParent, name);

            cur.Add(ne);
            return(ne);
        }
예제 #7
0
        public static void MoveFile(Recordset <EfsEntry> rs, int idFile, int idNewParent, string strNewName)
        {
            rs.filterFindEqual("id", idFile);
            if (!rs.applyFilter())
            {
                throw new FileNotFoundException();
            }

            EfsEntry ee = EfsEntry.NewFile(idNewParent, strNewName);

            rs.cursor.UpdateFields(ee, "idParent", "name");
            // rs.cursor.UpdateFields( ee, "idParent", "name", "dtAccess" );
        }
예제 #8
0
        public static EfsEntry CreateFolderEx(Cursor <EfsEntry> cur, int idParent, string path)
        {
            DirectoryInfo di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                throw new FileNotFoundException();
            }
            var ne = EfsEntry.NewFolder(idParent, di);

            cur.Add(ne);
            return(ne);
        }
예제 #9
0
        public static int CreateFolderRecursively(Recordset <EfsEntry> rs, int?idParent, IEnumerable <string> components)
        {
            if (!idParent.HasValue)
            {
                idParent = m_idRootFolder;
            }

            // Find existing portion.
            int?id = m_idRootFolder;

            IEnumerator <string> e = components.GetEnumerator();

            // Find existing part of the path
            while (true)
            {
                if (!e.MoveNext())
                {
                    return(id.Value);
                }
                int?idNext = FindFile(rs, id, e.Current);
                if (!idNext.HasValue)
                {
                    break;
                }

                /* bool? bIsDirectory = (bool?)rs.cursor.FetchSingleField( "isDirectory" );
                 * if( !bIsDirectory.HasValue || !bIsDirectory.Value )
                 *      return null; */

                id = idNext;
            }

            // Create missing part of the path
            rs.cursor.ResetIndex();

            while (true)
            {
                EfsEntry ne = EfsEntry.NewFolder(id.Value, e.Current);
                rs.cursor.Add(ne);
                id = ne.id;

                if (!e.MoveNext())
                {
                    return(id.Value);
                }
            }
        }
예제 #10
0
        public static EfsEntry AddFile(Recordset <EfsEntry> rs, int idParent, iFileIo io, string sourcePath, out long cbBytes)
        {
            FileInfo fi = new FileInfo(sourcePath);

            if (!fi.Exists)
            {
                throw new FileNotFoundException();
            }

            // Overwrite the old one
            int?idExisting = FindFile(rs, idParent, fi.Name);

            if (idExisting.HasValue)
            {
                DeleteFile(rs, idExisting.Value);
            }

            using (var trans = rs.session.BeginTransaction())
            {
                // Create a new one.
                var ne = EfsEntry.NewFile(idParent, fi);
                rs.cursor.Add(ne);
                trans.LazyCommitAndReopen();

                // Copy the data.
                rs.filterFindEqual("id", ne.id);
                ne = rs.getFirst();

                using (var stm = ne.data.Write(rs.cursor))
                    cbBytes = io.Read(stm, sourcePath);

                trans.Commit();

                return(ne);
            }
        }