Esempio n. 1
0
        EfsEntry AddFolder(iSerializerTransaction trans, int idParent, string strPath, ref int nFiles, ref long cbTotalBytes)
        {
            string name   = Path.GetFileName(strPath);
            int?   idFile = EFS.FindFile(rs, idParent, name);

            if (idFile.HasValue)
            {
                EFS.DeleteFile(rs, idFile.Value);
                trans.LazyCommitAndReopen();
            }

            EfsEntry res = EFS.CreateFolder(rs.cursor, idParent, name);

            idParent = res.id;
            // Inspired by http://stackoverflow.com/questions/2085452/fast-lowlevel-method-to-recursively-process-files-in-folders/2085872#2085872
            var pending = new Queue <Tuple <string, int> >();

            pending.Enqueue(Tuple.Create(strPath, idParent));

            string[] tmp;
            while (pending.Count > 0)
            {
                Tuple <string, int> p = pending.Dequeue();

                tmp = Directory.GetDirectories(p.Item1);
                foreach (var childFolder in tmp)
                {
                    name     = Path.GetFileName(childFolder);
                    idParent = EFS.CreateFolder(rs.cursor, p.Item2, name).id;
                    pending.Enqueue(Tuple.Create(childFolder, idParent));
                    trans.LazyCommitAndReopen();
                }

                tmp = Directory.GetFiles(p.Item1);
                foreach (var filePath in tmp)
                {
                    nFiles++;
                    long len;
                    EFS.AddFile(rs, p.Item2, fileIo, filePath, out len);
                    cbTotalBytes += len;
                    trans.LazyCommitAndReopen();
                }
            }

            return(res);
        }
Esempio n. 2
0
 int iSerializerSessionImpl.onTransactionBegin(iSerializerTransaction trans)
 {
     nOpened++;
     m_transactions.Push(trans);
     return(m_transactions.Count);
 }