Beispiel #1
0
        private static int VolumeMaintenance(VolumeMaintenanceOptions args)
        {
            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(args.LogPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + args.DatabasePath)) {
                    connection.Open();

                    if ((args.EnableVolume || args.DisableVolume) && !(args.EnableVolume && args.DisableVolume))
                    {
                        VolumeOperations.SetVolumeEnabledState(connection, args.Volume.Value, args.EnableVolume);
                    }

                    if (args.PurgeData)
                    {
                        // to do this we start a fake scan that isn't actually allowed to see/touch any file
                        var volumes = VolumeOperations.GetKnownVolumes(connection);
                        foreach (Volume v in volumes)
                        {
                            if (args.Volume.Value == v.ID)
                            {
                                ProcessVolume(textWriterWrapper.Writer, connection, v, fakeScan: true);
                            }
                        }
                    }

                    connection.Close();
                }

            return(0);
        }
Beispiel #2
0
 private static int ProcessArchiveScan(string logPath, string databasePath, string scanPath)
 {
     using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(logPath))
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + databasePath)) {
             connection.Open();
             ArchiveOperations.DoArchiveScan(textWriterWrapper.Writer, connection, scanPath);
             connection.Close();
         }
     return(0);
 }
Beispiel #3
0
        private static int ListVolumes(string logPath, string databasePath, bool showDisabledVolumes)
        {
            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(logPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + databasePath)) {
                    connection.Open();
                    PrintVolumeInformation(textWriterWrapper.Writer, VolumeOperations.GetKnownVolumes(connection).Where(x => showDisabledVolumes || x.ShouldScan));
                    connection.Close();
                }

            return(0);
        }
Beispiel #4
0
        private static int Search(SearchOptions args)
        {
            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(args.LogPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + args.DatabasePath)) {
                    connection.Open();
                    List <Volume> volumes = VolumeOperations.GetKnownVolumes(connection);
                    foreach (var sameFiles in CollectFiles(connection, GetFilesWithFilename(connection, "%" + args.File + "%"), (x) => true))
                    {
                        PrintSameFileInformation(textWriterWrapper.Writer, sameFiles, volumes);
                    }
                    connection.Close();
                }

            return(0);
        }
Beispiel #5
0
 private static int ProcessModifyArchive(string logPath, string databasePath, int archiveId, string addPath, string addPattern, DateTime begin, DateTime end)
 {
     using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(logPath))
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + databasePath)) {
             connection.Open();
             if (addPath != null)
             {
                 ArchiveOperations.AddPathToArchive(textWriterWrapper.Writer, connection, archiveId, addPath);
             }
             if (addPattern != null)
             {
                 ArchiveOperations.AddPatternToArchive(textWriterWrapper.Writer, connection, archiveId, addPattern, begin, end);
             }
             connection.Close();
         }
     return(0);
 }
Beispiel #6
0
        private static int ListFiles(string logPath, string databasePath, int?volume, bool selectedVolumeOnly, ShouldPrint shouldPrint)
        {
            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(logPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + databasePath)) {
                    connection.Open();

                    List <StorageFile> files   = GetKnownFilesOnVolume(connection, volume);
                    List <Volume>      volumes = VolumeOperations.GetKnownVolumes(connection);
                    foreach (var sameFiles in CollectFiles(connection, files, shouldPrint, selectedVolumeOnly ? volume : null))
                    {
                        PrintSameFileInformation(textWriterWrapper.Writer, sameFiles, volumes);
                    }

                    connection.Close();
                }

            return(0);
        }
Beispiel #7
0
        private static int ProcessNewArchive(string logPath, string databasePath)
        {
            int rv = -1;

            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(logPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + databasePath)) {
                    connection.Open();
                    using (IDbTransaction t = connection.BeginTransaction()) {
                        DatabaseHelper.CreateTables(t);
                        rv = HyoutaTools.SqliteUtil.Update(t, "INSERT INTO Archives DEFAULT VALUES") == 1 ? 0 : -1;
                        if (rv == 0)
                        {
                            t.Commit();
                        }
                    }
                    connection.Close();
                }
            return(rv);
        }
Beispiel #8
0
        private static int Scan(ScanOptions args)
        {
            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(args.LogPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + args.DatabasePath)) {
                    connection.Open();
                    using (IDbTransaction t = connection.BeginTransaction()) {
                        DatabaseHelper.CreateTables(t);
                        t.Commit();
                    }

                    var volumes = VolumeOperations.FindAndInsertAttachedVolumes(connection, args.Volume);
                    foreach (Volume v in volumes)
                    {
                        if (!args.Volume.HasValue || (args.Volume.Value == v.ID))
                        {
                            ProcessVolume(textWriterWrapper.Writer, connection, v);
                        }
                    }

                    connection.Close();
                }

            return(0);
        }
Beispiel #9
0
        public static int PrintExistingArchives(string logPath, string databasePath)
        {
            using (TextWriterWrapper textWriterWrapper = new TextWriterWrapper(logPath))
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + databasePath)) {
                    connection.Open();
                    List <Volume>  volumes  = VolumeOperations.GetKnownVolumes(connection);
                    List <Archive> archives = GetKnownArchives(connection);
                    connection.Close();

                    foreach (Archive a in archives)
                    {
                        textWriterWrapper.Writer.WriteLine("Archive #{0}:", a.ArchiveId);
                        foreach (ArchivePath p in a.Paths)
                        {
                            textWriterWrapper.Writer.WriteLine("  Volume #{0} {1}{2}", p.VolumeId, volumes.First(x => x.ID == p.VolumeId).Label, p.Path);
                        }
                        foreach (ArchivePattern p in a.Patterns)
                        {
                            textWriterWrapper.Writer.WriteLine("  Pattern #{0}: {1} from {2} to {3}", p.ArchivePatternId, p.Pattern, p.TimestampBegin, p.TimestampEnd);
                        }
                    }
                }
            return(0);
        }