예제 #1
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));
        }
예제 #2
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();
        }
예제 #3
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);
        }