Ejemplo n.º 1
0
        public async Task <List <FileIndexItem> > GeoBackgroundTaskAsync(
            string f   = "/",
            bool index = true,
            bool overwriteLocationNames = false)
        {
            if (!_iStorage.ExistFolder(f))
            {
                return(new List <FileIndexItem>());
            }
            // use relative to StorageFolder
            var listOfFiles = _iStorage.GetAllFilesInDirectory(f)
                              .Where(ExtensionRolesHelper.IsExtensionSyncSupported).ToList();

            var fileIndexList = _readMeta
                                .ReadExifAndXmpFromFileAddFilePathHash(listOfFiles);

            var toMetaFilesUpdate = new List <FileIndexItem>();

            if (index)
            {
                toMetaFilesUpdate =
                    _geoIndexGpx
                    .LoopFolder(fileIndexList);

                if (_appSettings.IsVerbose())
                {
                    Console.Write("¬");
                }

                await _geoLocationWrite
                .LoopFolderAsync(toMetaFilesUpdate, false);
            }

            fileIndexList =
                _geoReverseLookup
                .LoopFolderLookup(fileIndexList, overwriteLocationNames);

            if (fileIndexList.Count >= 1)
            {
                await _geoLocationWrite.LoopFolderAsync(
                    fileIndexList, true);
            }

            // Loop though all options
            fileIndexList.AddRange(toMetaFilesUpdate);

            // update thumbs to avoid unnecessary re-generation
            foreach (var item in fileIndexList.GroupBy(i => i.FilePath).Select(g => g.First())
                     .ToList())
            {
                var newThumb = new FileHash(_iStorage).GetHashCode(item.FilePath).Key;
                if (item.FileHash == newThumb)
                {
                    continue;
                }
                new ThumbnailFileMoveAllSizes(_thumbnailStorage).FileMove(item.FileHash, newThumb);
                if (_appSettings.IsVerbose())
                {
                    _logger.LogInformation("[/api/geo/sync] thumb rename + `" + item.FileHash + "`" + newThumb);
                }
            }

            return(fileIndexList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Command line importer to Database and update disk
        /// </summary>
        /// <param name="args">arguments provided by command line app</param>
        /// <returns>Void Task</returns>
        public async Task CommandLineAsync(string[] args)
        {
            _appSettings.Verbose = ArgsHelper.NeedVerbose(args);

            // Download ExifTool
            await _exifToolDownload.DownloadExifTool(_appSettings.IsWindows);

            // Geo cities1000 download
            await _geoFileDownload.Download();

            _appSettings.ApplicationType = AppSettings.StarskyAppType.Geo;

            if (new ArgsHelper().NeedHelp(args) ||
                (new ArgsHelper(_appSettings).GetPathFormArgs(args, false).Length <= 1 &&
                 ArgsHelper.GetSubPathFormArgs(args).Length <= 1 &&
                 new ArgsHelper(_appSettings).GetRelativeValue(args) == null))
            {
                new ArgsHelper(_appSettings, _console).NeedHelpShowDialog();
                return;
            }

            // Using both options
            string inputPath;

            // -s = if subPath || -p is path
            if (ArgsHelper.IsSubPathOrPath(args))
            {
                inputPath = _appSettings.DatabasePathToFilePath(
                    ArgsHelper.GetSubPathFormArgs(args)
                    );
            }
            else
            {
                inputPath = new ArgsHelper(_appSettings).GetPathFormArgs(args, false);
            }

            // overwrite subPath with relative days
            // use -g or --SubPathRelative to use it.
            // envs are not supported
            var getSubPathRelative = new ArgsHelper(_appSettings).GetRelativeValue(args);

            if (getSubPathRelative != null)
            {
                var dateTime = DateTime.Now.AddDays(( double )getSubPathRelative);
                inputPath = _appSettings.DatabasePathToFilePath(
                    new StructureService(_iStorage, _appSettings.Structure)
                    .ParseSubfolders(dateTime), false);
            }

            // used in this session to find the files back
            _appSettings.StorageFolder = inputPath;

            if (inputPath == null || _iStorage.IsFolderOrFile("/") == FolderOrFileModel.FolderOrFileTypeList.Deleted)
            {
                _console.WriteLine(
                    $"Folder location is not found \nPlease try the `-h` command to get help \nDid search for: {inputPath}");
                return;
            }

            // use relative to StorageFolder
            var listOfFiles = _iStorage.GetAllFilesInDirectory("/")
                              .Where(ExtensionRolesHelper.IsExtensionSyncSupported).ToList();

            var fileIndexList = _readMeta.ReadExifAndXmpFromFileAddFilePathHash(listOfFiles);

            var toMetaFilesUpdate = new List <FileIndexItem>();

            if (new ArgsHelper().GetIndexMode(args))
            {
                _console.WriteLine($"CameraTimeZone: {_appSettings.CameraTimeZone}");
                _console.WriteLine($"Folder: {inputPath}");

                toMetaFilesUpdate = new GeoIndexGpx(_appSettings,
                                                    _iStorage).LoopFolder(fileIndexList);

                _console.Write("¬");
                await _geoLocationWrite.LoopFolderAsync(toMetaFilesUpdate, false);

                _console.Write("(gps added)");
            }

            fileIndexList = _geoReverseLookup.LoopFolderLookup(fileIndexList,
                                                               ArgsHelper.GetAll(args));
            if (fileIndexList.Count >= 1)
            {
                _console.Write("~ Add city, state and country info ~");

                await _geoLocationWrite.LoopFolderAsync(fileIndexList, true);
            }

            _console.Write("^\n");
            _console.Write("~ Rename thumbnails ~");

            // Loop though all options
            fileIndexList.AddRange(toMetaFilesUpdate);

            // update thumbs to avoid unnecessary re-generation
            foreach (var item in fileIndexList.GroupBy(i => i.FilePath).
                     Select(g => g.First())
                     .ToList())
            {
                var newThumb = (await new FileHash(_iStorage).GetHashCodeAsync(item.FilePath)).Key;
                if (item.FileHash == newThumb)
                {
                    continue;
                }
                new ThumbnailFileMoveAllSizes(_thumbnailStorage).FileMove(
                    item.FileHash, newThumb);
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine("thumb+ `" + item.FileHash + "`" + newThumb);
                }
            }

            // dont updated in the database
        }