示例#1
0
        private void listBoxSystem_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBoxCore.ClearSelected();
            listBoxCore.Items.Clear();

            var system = (string)listBoxSystem.SelectedItem;

            if (system != null)
            {
                fillCores(system == Resources.Unassigned ? string.Empty : system);

                if (firstSelected != null)
                {
                    var game = firstSelected.Tag as NesApplication;
                    var core = string.IsNullOrEmpty(game.Metadata.Core) ? AppTypeCollection.GetAppBySystem(system).DefaultCore : game.Metadata.Core;
                    for (int i = 0; i < listBoxCore.Items.Count; ++i)
                    {
                        if (!(listBoxCore.Items[i] is CoreCollection.CoreInfo))
                        {
                            listBoxCore.SetSelected(i, true);
                        }
                        else if ((listBoxCore.Items[i] as CoreCollection.CoreInfo).Bin == core)
                        {
                            listBoxCore.SetSelected(i, true);
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        public static NesMiniApplication FromDirectory(string path, bool ignoreEmptyConfig = false)
        {
            var files = Directory.GetFiles(path, "*.desktop", SearchOption.TopDirectoryOnly);

            if (files.Length == 0)
            {
                throw new FileNotFoundException("Invalid app folder");
            }
            var config = File.ReadAllLines(files[0]);

            foreach (var line in config)
            {
                if (line.StartsWith("Exec="))
                {
                    string command = line.Substring(5);
                    var    app     = AppTypeCollection.GetAppByExec(command);
                    if (app != null)
                    {
                        var constructor = app.Class.GetConstructor(new Type[] { typeof(string), typeof(bool) });
                        return((NesMiniApplication)constructor.Invoke(new object[] { path, ignoreEmptyConfig }));
                    }
                    break;
                }
            }
            return(new NesMiniApplication(path, ignoreEmptyConfig));
        }
示例#3
0
        public static NesMiniApplication Import(string fileName, string zFileName, byte[] rawRomData = null)
        {
            var extension = Path.GetExtension(fileName).ToLower();

            if (extension == ".desktop")
            {
                return(ImportApp(fileName));
            }
            if (rawRomData == null)
            {
                rawRomData = File.ReadAllBytes(fileName);
            }
            var appinfo = AppTypeCollection.GetAppByExtension(extension);

            if (appinfo != null)
            {
                var import = appinfo.Class.GetMethod("Import", new Type[] { typeof(string), typeof(byte[]) });
                if (import != null)
                {
                    return((NesMiniApplication)import.Invoke(null, new object[] { fileName, rawRomData }));
                }
                else
                {
                    return(Import(fileName, zFileName, rawRomData, appinfo.Prefix, appinfo.DefaultApp, appinfo.DefaultCover, ConfigIni.Compress));
                }
            }
            string application = extension.Length > 2 ? ("/bin/" + extension.Substring(1)) : DefaultApp;

            return(Import(fileName, zFileName, rawRomData, DefaultPrefix, application, DefaultCover));
        }
示例#4
0
 private void textBox1_TextChanged(object sender, EventArgs e)
 {
     if (checkBox1.Checked)
     {
         if (textBox1.Text.Length > 0)
         {
             uint crc32 = Shared.CRC32(Encoding.UTF8.GetBytes(textBox1.Text.ToCharArray()));
             maskedTextBox1.Text = NesApplication.GenerateCode(crc32, AppTypeCollection.GetAvailablePrefix(textBox1.Text));
         }
         else
         {
             maskedTextBox1.Text = string.Empty;
         }
     }
 }
示例#5
0
        private void fillSystems()
        {
            if (systemsCollection == null)
            {
                systemsCollection = CoreCollection.Systems.ToList();
                foreach (var appInfo in AppTypeCollection.Apps)
                {
                    if (!systemsCollection.Contains(appInfo.Name))
                    {
                        systemsCollection.Add(appInfo.Name);
                    }
                }
                systemsCollection.Sort();
            }

            listBoxSystem.BeginUpdate();
            listBoxSystem.Items.Clear();
            listBoxSystem.Items.Add(Resources.Unassigned);
            var collection = showAllSystemsCheckBox.Checked || firstSelected == null ? (IEnumerable <string>)systemsCollection : CoreCollection.GetSystemsFromExtension(firstSelected.SubItems[1].Text.ToLower()).ToArray();

            if (collection.Any())
            {
                foreach (var system in collection.OrderBy(s => s))
                {
                    listBoxSystem.Items.Add(system);
                }
            }
            else
            {
                var appInfo = AppTypeCollection.GetAppByExtension(firstSelected.SubItems[1].Text.ToLower());
                if (!appInfo.Unknown)
                {
                    listBoxSystem.Items.Add(appInfo.Name);
                }
            }
            listBoxSystem.Enabled = true;
            listBoxSystem.EndUpdate();
        }
示例#6
0
        public static NesMiniApplication Import(string inputFileName, string originalFileName = null, byte[] rawRomData = null)
        {
            var extension = System.IO.Path.GetExtension(inputFileName).ToLower();

            if (extension == ".desktop")
            {
                return(ImportApp(inputFileName));
            }
            if (rawRomData == null)                            // Maybe it's already extracted data?
            {
                rawRomData = File.ReadAllBytes(inputFileName); // If not, reading file
            }
            if (originalFileName == null)                      // Original file name from archive
            {
                originalFileName = System.IO.Path.GetFileName(inputFileName);
            }
            char   prefix         = DefaultPrefix;
            string application    = extension.Length > 2 ? ("/bin/" + extension.Substring(1)) : DefaultApp;
            string args           = null;
            Image  cover          = DefaultCover;
            uint   crc32          = CRC32(rawRomData);
            string outputFileName = Regex.Replace(System.IO.Path.GetFileName(inputFileName), @"[^A-Za-z0-9()!\[\]\.\-]", "_").Trim();

            // Trying to determine file type
            var  appinfo = AppTypeCollection.GetAppByExtension(extension);
            bool patched = false;

            if (appinfo != null)
            {
                if (appinfo.DefaultApps.Length > 0)
                {
                    application = appinfo.DefaultApps[0];
                }
                prefix = appinfo.Prefix;
                cover  = appinfo.DefaultCover;
                var patch = appinfo.Class.GetMethod("Patch");
                if (patch != null)
                {
                    object[] values = new object[] { inputFileName, rawRomData, prefix, application, outputFileName, args, cover, crc32 };
                    var      result = (bool)patch.Invoke(null, values);
                    if (!result)
                    {
                        return(null);
                    }
                    rawRomData     = (byte[])values[1];
                    prefix         = (char)values[2];
                    application    = (string)values[3];
                    outputFileName = (string)values[4];
                    args           = (string)values[5];
                    cover          = (Image)values[6];
                    crc32          = (uint)values[7];
                    patched        = true;
                }
            }

            if (!patched)
            {
                FindPatch(ref rawRomData, inputFileName, crc32);
            }

            var code     = GenerateCode(crc32, prefix);
            var gamePath = Path.Combine(GamesDirectory, code);
            var romPath  = Path.Combine(gamePath, outputFileName);

            if (Directory.Exists(gamePath))
            {
                var files = Directory.GetFiles(gamePath, "*.*", SearchOption.AllDirectories);
                foreach (var f in files)
                {
                    try
                    {
                        File.Delete(f);
                    }
                    catch { }
                }
            }
            Directory.CreateDirectory(gamePath);
            File.WriteAllBytes(romPath, rawRomData);
            var game = new NesMiniApplication(gamePath, true);

            game.Name    = System.IO.Path.GetFileNameWithoutExtension(inputFileName);
            game.Name    = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim();
            game.Name    = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim();
            game.Name    = game.Name.Replace("_", " ").Replace("  ", " ").Trim();
            game.Command = $"{application} {GamesCloverPath}/{code}/{outputFileName}";
            if (!string.IsNullOrEmpty(args))
            {
                game.Command += " " + args;
            }
            game.FindCover(inputFileName, cover, crc32);
            game.Save();

            var app = NesMiniApplication.FromDirectory(gamePath);

            if (app is ICloverAutofill)
            {
                (app as ICloverAutofill).TryAutofill(crc32);
            }

            if (ConfigIni.Compress)
            {
                app.Compress();
            }

            return(app);
        }