public static string GetGameInfo(OBJConfig objConfig, RomDesc currentRom, CListBox romList)
        {
            // Rom Info
            var ranking = currentRom.PlayedTimeNow != TimeSpan.Zero ? currentRom.PlayedTimeNow.TotalSeconds / romList.MaxPlayedTimeNow.TotalSeconds : 0.0;
            var stars   = 0;

            if (ranking > 0.0)
            {
                stars = (int)Math.Round(ranking * 5, 0);
            }
            var perc = ranking > 0 ? Math.Round(ranking * 100, 0) : 0.0;
            var str  = "Ranking§" + perc + "%";

            if (stars > 0)
            {
                str += " (" + "".PadRight(stars, '*') + ")";
            }
            str += "\nPlayed§" + currentRom.PlayedCount + (currentRom.PlayedCount == 1 ? " time" : " times");
            str += "\nLast played§" + TimePassedBy(currentRom.TimeStamp);
            str += "\nTotal time§" + TimeSpent(currentRom.PlayedTime);
            var usage = romList.TotalPlayedTime.TotalSeconds > 0 ? Math.Round((currentRom.PlayedTime.TotalSeconds * 100) / romList.TotalPlayedTime.TotalSeconds, 0) : 0.0;

            str += "\nOn overall time§" + usage + "%";

            if (objConfig.current_platform == "all_emu")
            {
                str += "\n\nPlatform§" + currentRom.FeelInfo.PlatformDesc;
                str += "\nEmulator§" + currentRom.FeelInfo.EmulatorDesc;
            }

            return(str);
        }
        public static void UpdateRomStats(OBJConfig objConfig, RomDesc currentRom)
        {
            var statFileName = objConfig.current_platform == "all_emu" ? "all_emu" : objConfig.current_emulator;
            var filePath     = new StringBuilder(Application.StartupPath).Append(Path.DirectorySeparatorChar).Append("data")
                               .Append(Path.DirectorySeparatorChar).Append(statFileName).Append(".sts").ToString();

            if (!File.Exists(filePath))
            {
                var file = File.CreateText(filePath);
                file.Close();
            }
            var lines     = new List <string>(File.ReadAllLines(filePath));
            var lineValue = new StringBuilder(currentRom.Key).Append("|").Append(currentRom.PlayedCount).Append("|").Append(currentRom.PlayedTime).Append("|").Append(currentRom.TimeStamp.ToString("dd/MM/yyyy HH:mm:ss", cultureInfo)).ToString();
            var item      = lines.FindIndex(0, c => c.StartsWith(currentRom.Key + "|"));

            if (item >= 0)
            {
                lines[item] = lineValue;
            }
            else
            {
                lines.Add(lineValue);
            }
            File.WriteAllLines(filePath, lines.ToArray());
        }
 public static bool AddGameToList(OBJConfig objConfig, CListBox romList, RomDesc rom)
 {
     if (romList.AddGame(rom))
     {
         SaveRomList(objConfig, romList);
         return(true);
     }
     return(false);
 }
Beispiel #4
0
        public bool AddGame(RomDesc rom)
        {
            var found = _listBox.Find(c => c.Key == rom.Key);

            if (found != null)
            {
                return(false);
            }
            _listBox.Add(rom);
            CleanupSecondaryLists();

            return(true);
        }
Beispiel #5
0
 public RomDesc FindRom(RomDesc rom)
 {
     if (rom != null)
     {
         actIndex = FilteredList.FindIndex(c => c.Key == rom.Key);
     }
     UpdateSelection();
     if (actIndex != -1)
     {
         return(FilteredList[actIndex]);
     }
     else
     {
         return(rom);
     }
 }
Beispiel #6
0
        public RomDesc RemoveGame(RomDesc rom)
        {
            _listBox.RemoveAll(c => c.Key == rom.Key);
            CleanupSecondaryLists();

            if (actIndex > 0)
            {
                actIndex--;
            }

            UpdateSelection();
            if (actIndex >= 0 && FilteredList.Count > 0)
            {
                return(FilteredList[actIndex]);
            }
            return(null);
        }
        public static string GetGameHiscore(OBJConfig objConfig, RomDesc currentRom)
        {
            var str = string.Empty;

            if (objConfig.list_type == ListType.mame_xml_list)
            {
                // Hi-Score
                var hiscoreString = ReadHiscore(objConfig, objConfig.hiscore_path + Path.DirectorySeparatorChar + currentRom.Key + ".usr");
                if (hiscoreString.StartsWith("error", StringComparison.CurrentCultureIgnoreCase))
                {
                    hiscoreString = ReadHiscore(objConfig, objConfig.hiscore_path + Path.DirectorySeparatorChar + currentRom.Key + ".hi");
                    if (hiscoreString.StartsWith("error", StringComparison.CurrentCultureIgnoreCase))
                    {
                        hiscoreString = ReadHiscore(objConfig, objConfig.nvram_path + Path.DirectorySeparatorChar + currentRom.Key + ".nv");
                        if (hiscoreString.StartsWith("error", StringComparison.CurrentCultureIgnoreCase))
                        {
                            hiscoreString = string.Empty;
                        }
                    }
                }
                if (!string.IsNullOrEmpty(hiscoreString))
                {
                    var firstNRecords = 0;
                    var hiscoreShort  = string.Empty;
                    foreach (var line in hiscoreString.Split('\n'))
                    {
                        var cleanedline = line.Replace("\r", "");
                        if (cleanedline != string.Empty)
                        {
                            if (firstNRecords++ > 6)
                            {
                                break;
                            }
                            hiscoreShort += cleanedline + "\n";
                        }
                    }
                    hiscoreShort = hiscoreShort.Substring(0, hiscoreShort.Length - 1);
                    str         += "*#*TC*#*" + hiscoreShort.Replace('|', '§') + "*#*/T*#*";
                }
            }
            return(str);
        }
Beispiel #8
0
        public static bool SaveSnapShotFromClipboard(OBJConfig objConfig, RomDesc currentRom)
        {
            try
            {
                Bitmap screenShot = (Bitmap)Clipboard.GetImage();

                if (screenShot == null || objConfig.rotate_screen)
                {
                    var data   = Clipboard.GetData(DataFormats.Dib) as MemoryStream;
                    var buffer = data.ToArray();
                    int width  = 0;
                    int height = 0;
                    int bpp    = 0;
                    Utils.GetBitmapInfo(buffer, out width, out height, out bpp);
                    PixelFormat pixF;
                    switch (bpp)
                    {
                    case 8:
                        pixF = PixelFormat.Format8bppIndexed;
                        break;

                    case 16:
                        pixF = PixelFormat.Format16bppRgb565;
                        break;

                    case 24:
                        pixF = PixelFormat.Format24bppRgb;
                        break;

                    case 32:
                        pixF = PixelFormat.Format32bppRgb;
                        break;

                    default:
                        pixF = PixelFormat.Undefined;
                        break;
                    }
                    if (pixF != PixelFormat.Undefined)
                    {
                        screenShot = new Bitmap(width, height);
                        BitmapData bData = screenShot.LockBits(new System.Drawing.Rectangle(new System.Drawing.Point(), screenShot.Size), ImageLockMode.WriteOnly, pixF);
                        Marshal.Copy(buffer, 52, bData.Scan0, buffer.Length - 52);
                        screenShot.UnlockBits(bData);
                        if (objConfig.rotate_screen)
                        {
                            screenShot.RotateFlip(RotateFlipType.Rotate90FlipY);
                        }
                        else
                        {
                            screenShot.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        }
                    }
                }

                if (screenShot != null)
                {
                    if (!objConfig.screenshot_original_size)
                    {
                        Size size;
                        if (objConfig.screenshot_stretch_to_fixed_size)
                        {
                            size = objConfig.rotate_screen ? new Size(objConfig.screenshot_height, objConfig.screenshot_width) : new Size(objConfig.screenshot_width, objConfig.screenshot_height);
                        }
                        else
                        {
                            size = objConfig.rotate_screen ?
                                   Utils.ScaleDimension(screenShot.Height, screenShot.Width, objConfig.screenshot_height, objConfig.screenshot_width) :
                                   Utils.ScaleDimension(screenShot.Width, screenShot.Height, objConfig.screenshot_width, objConfig.screenshot_height);
                        }
                        if (screenShot.Width != objConfig.screenshot_width || screenShot.Height != objConfig.screenshot_height)
                        {
                            screenShot = Utils.ScaleBitmap(screenShot, size.Width, size.Height);
                        }
                    }
                    screenShot = Utils.RemoveBlackZoneFromBitmap(screenShot);
                    var fileName = objConfig.snapshot_path + Path.DirectorySeparatorChar + currentRom.Key + "." + objConfig.snapshot_extension;
                    screenShot.Save(fileName, objConfig.snapshot_extension.ToLower() == "jpg" ? ImageFormat.Jpeg : ImageFormat.Png);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Utils.PrintLog("Save Snapshot: " + ex.Message);
            }
            return(false);
        }
        public static List <RomDesc> BuildListFromPath(IFeel feel, OBJConfig objConfig, string romPath)
        {
            var dstList = new List <RomDesc>();

            if (Directory.Exists(romPath))
            {
                var fileList = Utils.GetFiles(romPath, objConfig.rom_extension);
                for (var iLoop = 0; iLoop < fileList.Length; iLoop++)
                {
                    var file        = fileList[iLoop];
                    var romName     = Path.GetFileNameWithoutExtension(file);
                    var romFileName = Path.GetFileName(file);
                    var item        = new RomDesc();
                    item.Key         = romName;
                    item.Description = LabelCleanup(romName);

                    var romRelativePath = fileList[iLoop].Substring(romPath.Length + 1); // skip initial backslash
                    romRelativePath = romRelativePath.Substring(0, romRelativePath.Length - romFileName.Length);

                    if (romRelativePath != string.Empty)
                    {
                        // remove trailing backslash
                        if (romRelativePath.Substring(romRelativePath.Length - 1) == Path.DirectorySeparatorChar.ToString())
                        {
                            romRelativePath = romRelativePath.Substring(0, romRelativePath.Length - 1);
                        }
                        item.RomRelativePath = romRelativePath;
                    }

                    dstList.Add(item);
                    if (iLoop % 100 == 0)
                    {
                        feel.ShowMessage("Adding available roms: " + iLoop + " of " + fileList.Length + "...", true);
                    }
                }

                var nmsFile = romPath + Path.DirectorySeparatorChar + objConfig.nms_file;
                if (File.Exists(nmsFile))
                {
                    var namingList = new List <NamingFile>();
                    var file       = File.OpenText(nmsFile);
                    while (!file.EndOfStream)
                    {
                        var line = file.ReadLine().Trim().ToString();
                        if (line.Contains("|"))
                        {
                            var split = line.Split('|');
                            var named = new NamingFile();
                            named.Description = split[0];
                            named.Name        = split[1];
                            namingList.Add(named);
                        }
                    }
                    file.Close();

                    foreach (var name in namingList)
                    {
                        var item = dstList.Find(c => c.Key.Equals(name.Name, StringComparison.CurrentCultureIgnoreCase));
                        if (item != null)
                        {
                            item.Description = name.Description;
                        }
                    }
                }
                feel.ShowToast("Done.");
            }
            else
            {
                feel.ShowMessage("\"" + romPath + "\" directory not found.\n\nPlease check " + objConfig.emulator_title + " \"rom_path\" parameter.", false);
            }

            return(dstList);
        }
Beispiel #10
0
        public static void SetLastPlayedGame(OBJConfig objConfig, RomDesc currentRom)
        {
            var lastPlayed = new GameRunChain(objConfig.current_platform, objConfig.current_emulator, objConfig.current_gamelist, currentRom.Key);

            objConfig.SetParameter("last_game_played", lastPlayed.ToString());
        }
Beispiel #11
0
        public static RomDesc RemoveGameFromList(OBJConfig objConfig, CListBox romList, RomDesc rom)
        {
            var currentRom = romList.RemoveGame(rom);

            SaveRomList(objConfig, romList);
            return(currentRom);
        }
Beispiel #12
0
        public static List <RomDesc> LoadRomList(OBJConfig objConfig)
        {
            var list     = new List <RomDesc>();
            var fileName = new StringBuilder(Application.StartupPath).Append(Path.DirectorySeparatorChar).Append("data")
                           .Append(Path.DirectorySeparatorChar).Append(objConfig.current_platform != "all_emu" ? objConfig.current_gamelist : "all_emu")
                           .Append(".lst").ToString();
            RomDesc rom;

            if (File.Exists(fileName))
            {
                var file = File.OpenText(fileName);
                while (!file.EndOfStream)
                {
                    if (objConfig.current_platform != "all_emu")
                    {
                        rom     = new RomDesc();
                        rom.Key = file.ReadLine();
                        rom.FeelInfo.RomName  = rom.Key;
                        rom.Description       = file.ReadLine();
                        rom.Year              = file.ReadLine();
                        rom.Manufacturer      = file.ReadLine();
                        rom.CloneOf           = file.ReadLine();
                        rom.Bios              = file.ReadLine();
                        rom.ExtraData         = file.ReadLine();
                        rom.ScreenOrientation = file.ReadLine();
                        rom.InputControl      = file.ReadLine();
                        rom.Status            = file.ReadLine();
                        rom.Color             = file.ReadLine();
                        rom.Sound             = file.ReadLine();
                        rom.Category          = file.ReadLine();
                    }
                    else
                    {
                        rom = new RomDesc(file.ReadLine());
                    }
                    list.Add(rom);
                }
                file.Close();
            }
            var statFileName = objConfig.current_platform == "all_emu" ? "all_emu" : objConfig.current_emulator;

            fileName = new StringBuilder(Application.StartupPath).Append(Path.DirectorySeparatorChar).Append("data")
                       .Append(Path.DirectorySeparatorChar).Append(statFileName).Append(".sts").ToString();
            if (File.Exists(fileName))
            {
                var file = File.OpenText(fileName);
                while (!file.EndOfStream)
                {
                    var arr = file.ReadLine().Split('|');
                    if (arr.Length > 3)
                    {
                        var romName     = arr[0];
                        var playedCount = int.Parse(arr[1]);
                        var playedTime  = TimeSpan.Parse(arr[2]);
                        var timeStamp   = DateTime.ParseExact(arr[3], "dd/MM/yyyy HH:mm:ss", cultureInfo);
                        rom = list.Find(c => c.Key == romName);
                        if (rom != null)
                        {
                            rom.PlayedCount = playedCount;
                            rom.PlayedTime  = playedTime;
                            rom.TimeStamp   = timeStamp;
                        }
                    }
                }
                file.Close();
            }
            if (!objConfig.show_clones && objConfig.current_gamelist == objConfig.current_emulator + "-0")
            {
                list.RemoveAll(c => c.CloneOf != "");
            }
            return(list);
        }
        private static RomDesc ReadRom(XmlReader reader, string mameBuild)
        {
            var xmlRom = reader.ReadSubtree();
            var rom    = new RomDesc();

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "name":
                    rom.Key = reader.Value;
                    break;

                case "cloneof":
                    rom.CloneOf = reader.Value;
                    break;

                case "romof":
                    rom.Bios = reader.Value;
                    break;

                case "isbios":
                    return(null);
                }
            }
            while (xmlRom.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.Name)
                    {
                    case "description":
                        try
                        {
                            reader.Read();
                            rom.Description = reader.Value;
                        }
                        catch
                        {
                            rom.Description = rom.Key;
                        }
                        break;

                    case "year":
                        reader.Read();
                        rom.Year = reader.Value;
                        break;

                    case "manufacturer":
                    case "publisher":
                        reader.Read();
                        rom.Manufacturer = reader.Value;
                        break;

                    case "rom":
                        break;

                    case "disk":
                        //rom.HaveCHDFile = true;
                        break;

                    case "chip":
                        break;

                    case "display":
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case "type":
                                rom.VideoType = reader.Value;
                                break;

                            case "rotate":
                                rom.ScreenOrientation = (reader.Value == "90" || reader.Value == "270") ? "Vertical" : "Horizontal";
                                break;

                            case "width":
                                //rom.Display.Width = Convert.ToInt32(reader.Value);
                                break;

                            case "height":
                                //rom.Display.Height = Convert.ToInt32(reader.Value);
                                break;
                            }
                        }
                        break;

                    case "sound":
                        break;

                    case "input":
                        var players = 0;
                        var control = string.Empty;
                        var buttons = 0;
                        // older listxml format (ex.: <input control="joy4way"...> )
                        if (mameBuild.CompareTo("0.106u12") <= 0)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                if (reader.Name == "players")
                                {
                                    players = int.Parse(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "control")
                                {
                                    if (!String.IsNullOrEmpty(control))
                                    {
                                        control += ",";
                                    }
                                    control += reader.Value;
                                    continue;
                                }
                                if (reader.Name == "buttons")
                                {
                                    buttons = int.Parse(reader.Value);
                                    continue;
                                }
                            }
                        }
                        else if (mameBuild.CompareTo("0.162") < 0)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                if (reader.Name == "buttons")
                                {
                                    buttons = int.Parse(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "players")
                                {
                                    players = int.Parse(reader.Value);
                                }
                            }

                            while (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "input")
                                {
                                    break;
                                }
                                if (reader.Name == "control")
                                {
                                    while (reader.MoveToNextAttribute())
                                    {
                                        if (reader.Name == "type")
                                        {
                                            if (!String.IsNullOrEmpty(control))
                                            {
                                                control += ",";
                                            }
                                            control += reader.Value;
                                            continue;
                                        }
                                    }
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                if (reader.Name == "buttons")
                                {
                                    buttons = int.Parse(reader.Value);
                                    continue;
                                }
                                if (reader.Name == "players")
                                {
                                    players = int.Parse(reader.Value);
                                }
                            }

                            while (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "input")
                                {
                                    break;
                                }
                                if (reader.Name == "control")
                                {
                                    while (reader.MoveToNextAttribute())
                                    {
                                        if (reader.Name == "type")
                                        {
                                            if (!String.IsNullOrEmpty(control))
                                            {
                                                control += ",";
                                            }
                                            control += reader.Value;
                                        }
                                        if (reader.Name == "ways")
                                        {
                                            control += reader.Value + "way";
                                            continue;
                                        }
                                    }
                                    continue;
                                }
                            }
                        }
                        rom.InputControl = control + (players > 0 ? (control != string.Empty ? " - " : string.Empty) + players + "P" : string.Empty) + (buttons > 0 ? " - " + buttons + "Bt" : string.Empty);
                        break;

                    case "driver":
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case "status":
                                rom.Status = reader.Value;
                                break;

                            case "emulation":
                                //rom.Driver.Emulation = reader.Value;
                                break;

                            case "color":
                                rom.Color = reader.Value;
                                break;

                            case "sound":
                                rom.Sound = reader.Value;
                                break;

                            case "graphic":
                                //rom.Driver.Graphic = reader.Value;
                                break;

                            case "protection":
                                //rom.Driver.Protection = reader.Value;
                                break;

                            case "savestate":
                                //rom.Driver.SaveState = reader.Value;
                                break;
                            }
                        }
                        break;
                    }
                    break;
                }
            }
            return(rom);
        }