Ejemplo n.º 1
0
        public void Start()
        {
            if (_started)
            {
                return;
            }

            var assetNames         = _assetManager.GetAllNames();
            var pathToAssetMapping = new Dictionary <string, string>();

            foreach (var name in assetNames)
            {
                var paths = _rawAssetLoader.GetPotentialPathsForRawAsset(name);

                foreach (var path in paths)
                {
                    pathToAssetMapping[path] = name;

                    var fi = new FileInfo(path);
                    if (!Directory.Exists(fi.Directory.FullName))
                    {
                        continue;
                    }

                    var watcher = new FileSystemWatcher();
                    watcher.Path         = fi.Directory.FullName;
                    watcher.Filter       = fi.Name;
                    watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName;
                    watcher.Changed     += new FileSystemEventHandler((sender, e) => {
                        _assetManager.Dirty(name);
                    });
                    watcher.Created += new FileSystemEventHandler((sender, e) => {
                        _assetManager.Dirty(name);
                    });
                    watcher.Deleted += new FileSystemEventHandler((sender, e) => {
                        _assetManager.Dirty(name);
                    });
                    watcher.Renamed += new RenamedEventHandler((sender, e) => {
                        if (pathToAssetMapping.ContainsKey(e.FullPath))
                        {
                            _assetManager.Dirty(pathToAssetMapping[e.FullPath]);
                        }

                        _assetManager.Dirty(name);
                    });
                    watcher.EnableRaisingEvents = true;
                }
            }

            _started = true;
        }