Пример #1
0
        private static void CalcHashAndAdd(byte[] bytes)
        {
            try
            {
                int    crc = DataAccess2.GetCrc32(bytes.AsSpan(3));
                string s   = DataAccess2.GetHash(crc);

                byte[] bytes2 = Encoding.UTF8.GetBytes(s);
                if (bytes2.Length == 16)
                {
                    DataAccess2.KEYS["Android"].TryAdd(bytes2, 0);
                    DataAccess2.KEYS["Browser"].TryAdd(bytes2, 0);
                    DataAccess2.KEYS["Standalone"].TryAdd(bytes2, 0);
                }
            }
            catch
            {
            }
        }
Пример #2
0
        internal static void Init(WebConfig webConfig)
        {
            if (string.IsNullOrWhiteSpace(webConfig.GamePath))
            {
                return;
            }

            PhysicalFileProvider val = new(webConfig.GamePath, ExclusionFilters.Sensitive)
            {
                UsePollingFileWatcher = true,
                UseActivePolling      = true
            };

            RefreshSwfs();
            RegisterWatch();

            void RefreshSwfs()
            {
                Console.WriteLine("Refreshing SWFs");

                Parallel.ForEach(new DirectoryInfo(webConfig.GamePath).GetFiles().OrderBy(f => f.LastWriteTime), async swf =>
                {
                    byte[] bytes = await System.IO.File.ReadAllBytesAsync(swf.FullName);

                    DataAccess2.CalcHashAndAdd(bytes);
                });
            }

            void RegisterWatch()
            {
                IChangeToken token = val.Watch("*.swf");

                token.RegisterChangeCallback(state =>
                {
                    RefreshSwfs();
                    RegisterWatch();
                }, null);
            }
        }