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);
             });
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 5
0
 public CacheItem Set(string key, FileSystemItem fileSystemItem, DateTime? expiration, DateTime? date, long? size)
 {
     return Set(key, fileSystemItem, expiration, date, size, null);
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 8
0
 public CacheItem Set(string key, FileSystemItem fileSystemItem, DateTime? expiration)
 {
     return Set(key, fileSystemItem, expiration, null, null, null);
 }
Exemplo n.º 9
0
 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));
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 public void ThrowCache(FileSystemItem item)
 {
     var cacheKey = GetCacheKey(item);
     if (cacheKey.Key != null) _cacheManager.Remove(cacheKey.Key);
 }
Exemplo n.º 12
0
 public void AddFile(FileSystemItem item)
 {
     _tree.Insert(item.Path, item);
 }
Exemplo n.º 13
0
 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;
     }
 }
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
0
        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;
            }
        }
Exemplo n.º 18
0
 public void UpdateTitle(string key, FileSystemItem item)
 {
     var cacheItem = _inMemoryCache[key.Hash()];
     cacheItem.Title = item.Title;
     cacheItem.Thumbnail = item.Thumbnail;
     ResetTimer();
 }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
 public CacheItem Set(string key, FileSystemItem fileSystemItem)
 {
     return Set(key, fileSystemItem, null, null, null, null);
 }
Exemplo n.º 21
0
 public ProfileItemWrapper(string path, FileSystemItem item, string errorMessage)
 {
     Path = path;
     Item = item;
     ErrorMessage = errorMessage;
 }
Exemplo n.º 22
0
 public TreeItemStream(FileSystemItem item) : base(0xFFFF)
 {
     _item = item;
     GenerateContent();
 }
Exemplo n.º 23
0
 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);
 }
Exemplo n.º 24
0
 public CacheItem GetCacheEntry(FileSystemItem item)
 {
     CacheComplexKey cacheKey;
     return GetCacheEntry(item, out cacheKey);
 }
Exemplo n.º 25
0
        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;
        }
Exemplo n.º 26
0
 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;
 }
Exemplo n.º 27
0
 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;
 }
Exemplo n.º 28
0
 public CacheItem GetCacheEntry(FileSystemItem item, out CacheComplexKey cacheKey)
 {
     cacheKey = GetCacheKey(item);
     return _cacheManager.Get(cacheKey);
 }
Exemplo n.º 29
0
 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;
 }
Exemplo n.º 31
0
 public QueueItem(FileSystemItem fileSystemItem, FileOperation fileOperation, object payload = null)
 {
     FileSystemItem = fileSystemItem;
     Operation      = fileOperation;
     Payload        = payload;
 }