// This one is the real. public Form1(SessionPool _pool) { InitializeComponent(); pool = _pool; sess = pool.GetSession(); rs = sess.Recordset <EfsEntry>(); EFS.Initialize(rs); fileIo = new FileIoThread(); // fileIo = new TrivialFileIo(); InitFoldersView(); }
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); } }