Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IOrderedEnumerable <KeyValuePair <string, List <UserGameInfo> > > GetInstalledGamesOrdered()
        {
            List <UserGameInfo> games = User.Games;
            Dictionary <string, List <UserGameInfo> > allGames = new Dictionary <string, List <UserGameInfo> >();

            for (int i = 0; i < games.Count; i++)
            {
                UserGameInfo game = games[i];
                if (!game.IsGamePresent())
                {
                    continue;
                }

                List <UserGameInfo> allSame;
                if (!allGames.TryGetValue(game.GameID, out allSame))
                {
                    allSame = new List <UserGameInfo>();
                    allGames.Add(game.GameID, allSame);
                }

                allSame.Add(game);
            }

            // <3 linq
            return(allGames.OrderBy(c => GameManager.Instance.MetadataManager.GetGameName(c.Key)));
        }
Beispiel #2
0
        public void GetIcon(UserGameInfo game, Action<Bitmap> callback) {
            Bitmap icon;
            if (GameIcons.TryGetValue(game.GameID, out icon)) {
                callback(icon);
            } else {
                // extract icon from exe file
                lock (callbacks) {
                    List<Action<Bitmap>> calls;
                    if (!callbacks.TryGetValue(game.GameID, out calls)) {
                        calls = new List<Action<Bitmap>>();
                        callbacks.Add(game.GameID, calls);

                        ThreadPool.QueueUserWorkItem(ThreadGetIcon, game);
                    }
                    calls.Add(callback);
                }

            }
        }
Beispiel #3
0
        /// <summary>
        /// Tries adding a game to the collection with the provided executable path
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath)
        {
            string lower = exePath.ToLower();
            string dir   = Path.GetDirectoryName(exePath);

            var possibilities = GetAllHandlers(exePath);

            foreach (GameHandlerMetadata metadata in possibilities)
            {
                // check if the Context matches
                string[] context = metadata.ExeContext;
                bool     notAdd  = false;
                if (context != null)
                {
                    for (int j = 0; j < context.Length; j++)
                    {
                        string con = Path.Combine(dir, context[j]);
                        if (!File.Exists(con) &&
                            !Directory.Exists(con))
                        {
                            notAdd = true;
                            break;
                        }
                    }
                }

                if (notAdd ||
                    User.Games.Any(c => c.ExePath.ToLower() == lower))
                {
                    continue;
                }

                Log.WriteLine($"Found game: {metadata.Title}, on path: {exePath}");
                UserGameInfo uinfo = new UserGameInfo();
                uinfo.InitializeDefault(metadata, exePath);
                User.Games.Add(uinfo);
                User.Save();

                return(uinfo);
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Tries adding a game to the collection with the provided IGameInfo
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath, GameHandlerMetadata metadata)
        {
            string lower = exePath.ToLower();
            string dir   = Path.GetDirectoryName(exePath);

            if (User.Games.Any(c => c.ExePath.ToLower() == lower))
            {
                return(null);
            }

            Log.WriteLine($"Added game: {metadata.Title}, on path: {exePath}");
            UserGameInfo uinfo = new UserGameInfo();

            uinfo.InitializeDefault(metadata, exePath);
            User.Games.Add(uinfo);
            User.Save();

            return(uinfo);
        }
Beispiel #5
0
        private void ThreadGetIcon(object state) {
            UserGameInfo game = (UserGameInfo)state;
            Icon icon = Shell32Interop.GetIcon(game.ExePath, false);

            Bitmap bmp = icon.ToBitmap();
            icon.Dispose();
            game.Icon = bmp;

            lock (callbacks) {
                List<Action<Bitmap>> calls;
                if (callbacks.TryGetValue(game.GameID, out calls)) {
                    for (int i = 0; i < calls.Count; i++) {
                        calls[i](bmp);
                    }
                    callbacks.Remove(game.GameID);
                }

                GameIcons.Add(game.GameID, bmp);
            }
        }
Beispiel #6
0
 public abstract bool Initialize(GameHandler handler, HandlerData handlerData, UserGameInfo game, GameProfile profile);