public static int AddPathToArchive(TextWriter writer, SQLiteConnection connection, long archiveId, string path) { List <Volume> volumes = VolumeOperations.FindAndInsertAttachedVolumes(connection); string devId = Win32Util.FindVolumeIdFromPath(path); Volume vol = volumes.First(x => x.DeviceID == devId); // messy nonsense var fi = new FileInfo(path); string subpath = fi.FullName.Substring(Path.GetPathRoot(fi.FullName).Length).Replace("\\", "/"); if (!subpath.StartsWith("/")) { subpath = "/" + subpath; } if (subpath.EndsWith("/")) { subpath = subpath.Substring(0, subpath.Length - 1); } if (subpath == "" || subpath == "/") { return(-1); } using (IDbTransaction t = connection.BeginTransaction()) { long pathId = DatabaseHelper.InsertOrUpdatePath(t, vol.ID, subpath); HyoutaTools.SqliteUtil.Update(t, "INSERT INTO ArchivePaths (archiveId, pathId) VALUES (?, ?)", new object[] { archiveId, pathId }); t.Commit(); } return(0); }
public static List <Volume> FindAndInsertAttachedVolumes(SQLiteConnection connection, int?onlyVolumeId = null) { List <Volume> volumes = new List <Volume>(); foreach (Win32Volume vol in Win32Util.GetAttachedVolumes()) { Volume v = CreateOrFindVolume(connection, vol.Id, vol.Label, (long)vol.Capacity, (long)vol.FreeSpace, onlyVolumeId); if (v != null) { volumes.Add(v); } } return(volumes); }