public void Recognize(FileSystemItem item, Action<int> success, Action<Exception> error) { ProgressMessage = Resx.OpeningProfile; this.NotifyProgressStarted(); WorkHandler.Run(() => RecognizeFromProfile(item), result => { this.NotifyProgressFinished(); if (success != null) success.Invoke(result); }, exception => { this.NotifyProgressFinished(); if (error != null) error.Invoke(exception); }); }
public bool RecognizeType(FileSystemItem item) { var recognition = RecognizeByName(item.Name, item.Type); if (recognition == null) return false; item.TitleType = recognition.TitleType; if (recognition.TitleType == TitleType.Content) { var content = BitConverter.ToInt32(item.Name.FromHex(), 0); if (Enum.IsDefined(typeof (ContentType), content)) { item.ContentType = (ContentType) content; item.Title = GetContentTypeTitle(item.ContentType); } } else { item.Title = recognition.Title; } return true; }
public override IList<FileSystemItem> GetDrives() { var drives = DriveInfo.GetDrives(); var result = new List<FileSystemItem>(); foreach (var drive in drives) { var name = drive.Name.TrimEnd('\\'); string icon; string fullPath = null; switch (drive.DriveType) { case DriveType.CDRom: icon = "drive_cd"; break; case DriveType.Network: icon = "drive_network"; var sb = new StringBuilder(512); var size = sb.Capacity; if (WNetGetConnection(name, sb, ref size) == 0) fullPath = sb.ToString().TrimEnd(); break; case DriveType.Removable: icon = "drive_flash"; if (!drive.IsReady) continue; break; default: icon = "drive"; break; } var item = new FileSystemItem { Path = drive.Name, FullPath = fullPath ?? drive.Name, Name = name, Type = ItemType.Drive, Thumbnail = ResourceManager.GetContentByteArray(string.Format("/Resources/{0}.png", icon)) }; result.Add(item); } return result; }
private int RecognizeFromProfile(FileSystemItem item) { _titleUpdated = -1; EventAggregator.GetEvent<TransferProgressChangedEvent>().Subscribe(OnGetBinaryContentProgressChanged); var content = _titleRecognizer.GetBinaryContent(item); EventAggregator.GetEvent<TransferProgressChangedEvent>().Unsubscribe(OnGetBinaryContentProgressChanged); if (content != null) { var stfs = ModelFactory.GetModel<StfsPackage>(content); UIThread.Run(() => { ProgressMessage = Resx.ScanningProfile; ProgressValue = 0; }); stfs.ContentCountDetermined += OnStfsContentCountDetermined; stfs.ContentParsed += OnStfsContentParsed; stfs.ExtractGames(); stfs.ContentCountDetermined -= OnStfsContentCountDetermined; stfs.ContentParsed -= OnStfsContentParsed; } return _titleUpdated; }
public CacheItem Set(string key, FileSystemItem fileSystemItem, DateTime? expiration, DateTime? date, long? size) { return Set(key, fileSystemItem, expiration, date, size, null); }
public CacheItem Set(string key, FileSystemItem fileSystemItem, DateTime? expiration, DateTime? date, long? size, byte[] content) { var hashKey = key.Hash(); var entry = new CacheItem { Id = hashKey, Expiration = expiration, Date = date, Size = size, Title = fileSystemItem.Title, Type = (int)fileSystemItem.Type, TitleType = (int)fileSystemItem.TitleType, ContentType = (int)fileSystemItem.ContentType, RecognitionState = (int)fileSystemItem.RecognitionState, Thumbnail = fileSystemItem.Thumbnail, Content = content }; _inMemoryCache.Remove(hashKey); _inMemoryCache.Add(hashKey, entry); ResetTimer(); return entry; }
private CacheItem SaveDataFileCache(CacheComplexKey cacheKey, FileSystemItem item) { if (item.RecognitionState == RecognitionState.Recognized) { var svodExpiration = GetExpirationFrom(_userSettingsProvider.XboxLiveContentExpiration); return _userSettingsProvider.XboxLiveContentInvalidation ? _cacheManager.Set(cacheKey.Key, item, svodExpiration, item.Date, item.Size) : _cacheManager.Set(cacheKey.Key, item, svodExpiration); } return _cacheManager.Set(cacheKey.Key, item, GetExpirationFrom(_userSettingsProvider.UnknownContentExpiration)); }
public CacheItem Set(string key, FileSystemItem fileSystemItem, DateTime? expiration) { return Set(key, fileSystemItem, expiration, null, null, null); }
public bool CopyStream(FileSystemItem item, Stream stream, long startPosition = 0, long? byteLimit = null) { return CopyStream(item.Path, stream, startPosition, byteLimit ?? item.Size ?? FileExists(item.Path)); }
private CacheComplexKey GetCacheKey(FileSystemItem item) { var key = new CacheComplexKey(); switch (item.TitleType) { case TitleType.SystemDir: case TitleType.SystemFile: case TitleType.Content: key.Item = item; key.Key = item.Name; break; case TitleType.Game: key.Item = item; key.Key = item.Type == ItemType.File ? item.Name.Replace(".gpd", string.Empty) : item.Name; break; case TitleType.Profile: if (item.Type == ItemType.File) { key.Item = item; key.Key = item.FullPath; } else { var recognition = GetProfileItem(item); key.Item = recognition.Item; key.Key = recognition.Path; key.ErrorMessage = recognition.ErrorMessage; } break; case TitleType.DataFile: key.Item = item; key.Key = item.FullPath; break; } if (key.Item != null) { key.Size = key.Item.Size; key.Date = key.Item.Date; } return key; }
public void ThrowCache(FileSystemItem item) { var cacheKey = GetCacheKey(item); if (cacheKey.Key != null) _cacheManager.Remove(cacheKey.Key); }
public void AddFile(FileSystemItem item) { _tree.Insert(item.Path, item); }
private bool GetGameDataFromGpd(FileSystemItem item) { try { var fileContent = _fileManager.ReadFileContent(item.Path); var gpd = ModelFactory.GetModel<GameFile>(fileContent); gpd.Parse(); if (gpd.Strings.Count > 0) item.Title = gpd.Strings.First().Text; item.Thumbnail = gpd.Thumbnail; item.RecognitionState = RecognitionState.Recognized; return true; } catch { return false; } }
public bool UpdateTitle(FileSystemItem item) { var cacheKey = GetCacheKey(item); var cacheItem = _cacheManager.Get(cacheKey); if (cacheItem == null) return false; if (_cacheManager.ContainsKey(cacheKey.Key)) { _cacheManager.UpdateTitle(cacheKey.Key, item); } else { switch (item.TitleType) { case TitleType.Game: SaveGameCache(cacheKey, item); break; case TitleType.Profile: SaveProfileCache(cacheKey, item, null); break; case TitleType.Content: _cacheManager.Set(cacheKey.Key, item); break; case TitleType.DataFile: SaveDataFileCache(cacheKey, item); break; } } return true; }
private bool GetGameDataFromUnity(FileSystemItem item) { string title = null; byte[] thumbnail = null; var result = false; try { var request = WebRequest.Create(string.Format("http://xboxunity.net/Resources/Lib/TitleList.php?search={0}", item.Name)); var response = request.GetResponse(); var stream = response.GetResponseStream(); if (stream != null) { var responseReader = new StreamReader(stream); var json = responseReader.ReadToEnd(); var unityResponse = json.FromJson<UnityResponse>(); var firstResult = unityResponse.Items.FirstOrDefault(); title = firstResult != null ? firstResult.Name.Trim() : null; result = !string.IsNullOrEmpty(title); if (result) { request = WebRequest.Create(string.Format("http://xboxunity.net/Resources/Lib/Icon.php?tid={0}", item.Name)); response = request.GetResponse(); stream = response.GetResponseStream(); if (stream != null && response.ContentType == "image/png") { var ms = new MemoryStream(); stream.CopyTo(ms); thumbnail = ms.GetBuffer(); } } } } catch {} if (result) { item.Title = title; if (thumbnail != null) { item.Thumbnail = thumbnail; item.RecognitionState = RecognitionState.Recognized; } else { UIThread.Run(() => _eventAggregator.GetEvent<NotifyUserMessageEvent>().Publish(new NotifyUserMessageEventArgs("PartialRecognitionMessage", MessageIcon.Warning))); item.Thumbnail = _resourceManager.GetContentByteArray("/Resources/xbox_logo.png"); item.RecognitionState = RecognitionState.PartiallyRecognized; } } return result; }
private bool GetGameData(FileSystemItem item) { var infoFileFound = false; var systemdir = item.Name.StartsWith("5841") ? "000D0000" : "00007000"; var gamePath = string.Format("{0}{1}", item.Path, systemdir); var exists = _fileManager.FolderExists(gamePath); if (!exists) { var r = new Regex(@"(?<content>Content[\\/])E0000[0-9A-F]{11}", RegexOptions.IgnoreCase); if (r.IsMatch(gamePath)) { gamePath = r.Replace(gamePath, "${content}0000000000000000"); exists = _fileManager.FolderExists(gamePath); } } if (!exists) return false; try { var file = _fileManager.GetList(gamePath).FirstOrDefault(i => i.Type == ItemType.File); if (file != null) { var fileContent = _fileManager.ReadFileContent(file.Path, StfsPackage.DefaultHeaderSizeVersion1); var svod = ModelFactory.GetModel<SvodPackage>(fileContent); if (svod.IsValid) { item.Title = svod.TitleName; item.Thumbnail = svod.ThumbnailImage; item.ContentType = svod.ContentType; item.RecognitionState = RecognitionState.Recognized; infoFileFound = true; } } } catch { } return infoFileFound; }
private byte[] GetProfileData(FileSystemItem item, FileSystemItem cacheItem) { if (cacheItem == null) return null; try { var bytes = _fileManager.ReadFileContent(cacheItem.Path); var stfs = ModelFactory.GetModel<StfsPackage>(bytes); stfs.ExtractAccount(); item.Title = stfs.Account.GamerTag; item.Thumbnail = stfs.ThumbnailImage; item.ContentType = stfs.ContentType; item.RecognitionState = RecognitionState.Recognized; return bytes; } catch (Exception ex) { item.IsLocked = true; //TODO: exception message in non-English environment item.LockMessage = ex.Message == "Permission denied" || ex.Message == "Could not open file" ? Resx.ProfileIsInUseErrorMessage : ex.Message; return null; } }
public void UpdateTitle(string key, FileSystemItem item) { var cacheItem = _inMemoryCache[key.Hash()]; cacheItem.Title = item.Title; cacheItem.Thumbnail = item.Thumbnail; ResetTimer(); }
public byte[] GetBinaryContent(FileSystemItem item) { var cacheKey = GetCacheKey(item); var cacheEntry = _cacheManager.Get(cacheKey); if (cacheEntry == null) { cacheEntry = RecognizeTitle(item); if (cacheEntry == null) { throw new ApplicationException(string.Format("Item cannot be recognized anymore: {0}", cacheKey.Item.Path)); } } return _cacheManager.GetBinaryContent(cacheKey.Key); }
public CacheItem Set(string key, FileSystemItem fileSystemItem) { return Set(key, fileSystemItem, null, null, null, null); }
public ProfileItemWrapper(string path, FileSystemItem item, string errorMessage) { Path = path; Item = item; ErrorMessage = errorMessage; }
public TreeItemStream(FileSystemItem item) : base(0xFFFF) { _item = item; GenerateContent(); }
public void UpdateEntry(string key, FileSystemItem content) { if (content == null) { Debugger.Break(); } var hashKey = HashKey(key); if (!_cacheStore.ContainsKey(hashKey)) { SaveEntry(key, content); return; } var item = Get(hashKey); item.Content = content; item.Expiration = null; _inMemoryCache.Remove(hashKey); _inMemoryCache.Add(hashKey, item); _cacheStore.Update(hashKey, item); }
public CacheItem GetCacheEntry(FileSystemItem item) { CacheComplexKey cacheKey; return GetCacheEntry(item, out cacheKey); }
private ProfileItemWrapper GetProfileItem(FileSystemItem item) { const string pattern = "{1}FFFE07D1{2}00010000{2}{0}"; var profileFullPath = string.Format(pattern, item.Name, item.FullPath, _fileManager.Slash); string message = null; if (_profileFileCache.ContainsKey(profileFullPath)) return _profileFileCache[profileFullPath]; var profilePath = string.Format(pattern, item.Name, item.Path, _fileManager.Slash); var profileItem = _fileManager.GetItemInfo(profilePath); if (profileItem != null) { if (profileItem.Type == ItemType.File) { RecognizeType(profileItem); } else { profileItem = null; message = Resx.ProfileIsInUseErrorMessage; } } else { message = Resx.ProfileDoesntExistErrorMessage; } var wrapper = new ProfileItemWrapper(profileFullPath, profileItem, message); _profileFileCache.Add(profileFullPath, wrapper); return wrapper; }
public CacheEntry<FileSystemItem> SaveEntry(string key, FileSystemItem content, DateTime? expiration = null, DateTime? date = null, long? size = null, string tmpPath = null) { if (content == null) { Debugger.Break(); } var entry = new CacheEntry<FileSystemItem> { Expiration = expiration, Date = date, Size = size, Content = content, TempFilePath = tmpPath }; var hashKey = HashKey(key); _inMemoryCache.Remove(hashKey); _inMemoryCache.Add(hashKey, entry); _cacheStore.Update(hashKey, entry); return entry; }
private CacheItem SaveProfileCache(CacheComplexKey cacheKey, FileSystemItem item, byte[] content) { var profileExpiration = GetExpirationFrom(_userSettingsProvider.ProfileExpiration); item.IsCached = true; var cacheItem = _userSettingsProvider.ProfileInvalidation ? _cacheManager.Set(cacheKey.Key, item, profileExpiration, cacheKey.Date, cacheKey.Size, content) : _cacheManager.Set(cacheKey.Key, item, profileExpiration); _cacheManager.Set(item.Name, item); return cacheItem; }
public CacheItem GetCacheEntry(FileSystemItem item, out CacheComplexKey cacheKey) { cacheKey = GetCacheKey(item); return _cacheManager.Get(cacheKey); }
private CacheItem SaveGameCache(CacheComplexKey cacheKey, FileSystemItem item) { var gameExpiration = GetGameExpiration(item.RecognitionState); item.IsCached = true; return _cacheManager.Set(cacheKey.Key, item, GetExpirationFrom(gameExpiration)); }
private bool IsCopy(FileSystemItem a, FileSystemItem b) { //TODO return a.Name == b.Name; }
public QueueItem(FileSystemItem fileSystemItem, FileOperation fileOperation, object payload = null) { FileSystemItem = fileSystemItem; Operation = fileOperation; Payload = payload; }