Exemple #1
0
        public async override Task GetFiles()
        {
            InitCollections();

            //Get lamp files
            _lampshowPath = Path.Combine(_skeletonGameProvider.GameFolder, "assets\\lampshows");
            if (!Directory.Exists(_lampshowPath))
            {
                Log($"Creating lampshow directory. {_lampshowPath}");
                Directory.CreateDirectory(_lampshowPath);
            }

            Log($"Retrieving Lamp/RGB Shows from {_lampshowPath}");
            this.AssetFiles = new ObservableCollection <string>();
            var lampshowFiles = await _skeletonGameFiles.GetFilesAsync(_lampshowPath, AssetTypes.Lampshows);

            foreach (var lampshow in lampshowFiles)
            {
                var lampFile = Path.GetFileName(lampshow);
                if (lampFile.Contains(".lampshow"))
                {
                    if (!LampShows.Any(x => x.File == lampFile))
                    {
                        await Dispatcher.CurrentDispatcher.InvokeAsync(() =>
                        {
                            AssetFiles.Add(lampFile);
                        });
                    }
                }
                else if (lampFile.Contains(".rgbshow"))
                {
                    if (!RGBShows.Any(x => x.File == lampFile))
                    {
                        await Dispatcher.CurrentDispatcher.InvokeAsync(() =>
                        {
                            AssetFiles.Add(lampFile);
                        });
                    }
                }
            }
        }
        internal void GetAssetAttr(ReadOnlySpan <byte> path, Span <byte> link, ref stat stat, Guid fileuuid)
        {
            // Even though we have the id of the asset, we actually need the entry from BakedFiles,
            // which should have the last stat on it - or we use FileInfo in the sql database - maybe we'll do both
            // The asset might exist as lots of different files with lots of date (though only one size)

            if (debug)
            {
                Console.WriteLine($"Found Tag: {RawDirs.HR(path)}={RawDirs.HR(link)}");
            }

            // Had to find/build a python compatible uuid5 -- the guidex module does not make valid uuid5s
            //var fileuuid = Guid.Empty;
            //if (fiRef.ExtFileHandle.HasValue)
            //    fileuuid = fiRef.ExtFileHandle.Value;

            if (assetFiles == null)
            {
                assetFiles = NeoMongo.NeoDb.AssetFiles();
            }

            AssetFiles aRec = null;

            try
            {
                var volFilter = Builders <AssetFiles> .Filter.Eq("_id", fileuuid.ToString().ToLower());

                aRec = assetFiles.FindSync(volFilter).FirstOrDefault();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: ${ex.Message}");
            }

            if (aRec != null)
            {
                // These should be synthesized - eventually we'll have more security here - for now
                //   all owned by neo:neo and world readable
                //stat.st_mode = (mode_t) aRec.Stat.mode;
                //stat.st_mode = S_IFREG | 0b100_100_100; // r--r--r--
                stat.st_nlink = 1;
                stat.st_mode  = LibC.S_IFREG | (mode_t)0b100_100_100; // 444 protection for now
                stat.st_uid   = 10010;                                // aRec.Stat.uid;
                stat.st_gid   = 10010;                                // aRec.Stat.gid;

                if (aRec.Stat != null)
                {
                    stat.st_size = aRec.Stat.size;

                    stat.st_ctim = new timespec
                    {
                        tv_sec  = aRec.Stat.ctime,
                        tv_nsec = 0
                    };
                    stat.st_mtim = new timespec
                    {
                        tv_sec  = aRec.Stat.mtime,
                        tv_nsec = 0
                    };
                    stat.st_atim = new timespec
                    {
                        tv_sec  = aRec.Stat.atime,
                        tv_nsec = 0
                    };
                }
                else
                {
                    // Just turn the link into our stat, we'll just keep the dates and make it into a file
                    stat.st_nlink = 1;
                    stat.st_mode  = LibC.S_IFREG | (mode_t)0b100_100_100; // 444 protection for now
                    stat.st_uid   = 10010;                                // aRec.Stat.uid;
                    stat.st_gid   = 10010;                                // aRec.Stat.gid;

                    Console.WriteLine($"No internal Stat: {RawDirs.HR(path)}={RawDirs.HR(link)}");
                }

                if (debug)
                {
                    Console.WriteLine($"Stat Asset Dump: size={stat.st_size}, mode={stat.st_mode}, mtim={stat.st_mtim}");
                }
                if (debug)
                {
                    Console.WriteLine($"Return stat for: {fileuuid.ToString().ToLower()}");
                }

                return;
            }

            Console.WriteLine($"Can't find AssetFile: {fileuuid.ToString().ToLower()}");
        }