Beispiel #1
0
        private string BuildFullGamePath(string GamesFolder, string GamePath)
        {
            string path = string.Empty;

            // check whether relative or absolute path has been set in the database for this game
            if (RomPath.StartsWith("."))
            {
                // path is relative (rom autoimported from defined path) - build path
                path = GamesFolder + GamePath;
            }
            else
            {
                // rom or disk has been manually added with full path - return just full path
                path = GamePath;
            }

            // now do 7zip processing if neccesary
            string extension = System.IO.Path.GetExtension(path).ToLower();

            if (extension == ".7z")
            {
                /* 7zip archive detected - extract contents to cache directory and modify path variable accordingly */

                // create cache directory if it does not exist
                string cacheDir = AppDomain.CurrentDomain.BaseDirectory + "Data\\Cache";
                Directory.CreateDirectory(cacheDir);

                // inspect the archive
                Archiving arch = new Archiving(path, SystemId);
                arch.ProcessArchive();

                // get filename
                string filename = arch.FileName;

                // get filesize
                long filesize = arch.FileSize;

                // check whether file already exists in cache
                string cacheFile = cacheDir + "\\" + filename;
                if (File.Exists(cacheFile))
                {
                    // file exists - check size
                    long length = new System.IO.FileInfo(cacheFile).Length;

                    if (length != filesize)
                    {
                        arch.ExtractArchive(cacheDir);
                    }
                }
                else
                {
                    // extract contents of archive to cache folder
                    arch.ExtractArchive(cacheDir);
                }

                // return the new path to the rom
                return(cacheFile);
            }

            return(path);
        }
Beispiel #2
0
        public string BuildFullGamePath(string GamesFolder, string GamePath)
        {
            string path      = string.Empty;
            string extension = string.Empty;

            // check whether relative or absolute path has been set in the database for this game
            if (RomPath.StartsWith("."))
            {
                // path is relative (rom autoimported from defined path) - build path
                path = GamesFolder + GamePath.TrimStart('.');
            }
            else
            {
                // rom or disk has been manually added with full path - return just full path
                path = GamePath;
            }

            // create cache directory if it does not exist
            string cacheDir = AppDomain.CurrentDomain.BaseDirectory + "Data\\Cache";

            Directory.CreateDirectory(cacheDir);

            /* now do archive processing */
            if (path.Contains("*/"))
            {
                // this is an archive file with a direct reference to a ROM inside
                string[] arr         = path.Split(new string[] { "*/" }, StringSplitOptions.None);
                string   archivePath = arr[0];
                string   archiveFile = arr[1];

                // copy specific rom from archive to cache folder and get cache rom path
                string cacheRom = Archive.ExtractFile(archivePath, archiveFile, cacheDir); //Archiving.SetupArchiveChild(archivePath, archiveFile, cacheDir);

                if (cacheRom != string.Empty)
                {
                    return(ParseSMD(cacheRom, cacheDir));
                }
            }
            else if (path.ToLower().Contains(".7z") || path.ToLower().Contains(".zip"))
            {
                // This is a standard archive with no defined link
                extension = System.IO.Path.GetExtension(path).ToLower();

                if (extension == ".zip") //zip
                {
                    // this should be a zip file with a single rom inside - pass directly to mednafen as is
                    using (System.IO.Compression.ZipArchive ar = System.IO.Compression.ZipFile.OpenRead(path))
                    {
                        foreach (System.IO.Compression.ZipArchiveEntry entry in ar.Entries)
                        {
                            if (entry.FullName.EndsWith(".smd", StringComparison.OrdinalIgnoreCase))
                            {
                                entry.Archive.ExtractToDirectory(cacheDir, true);
                                return(ParseSMD(Path.Combine(cacheDir, entry.FullName), cacheDir));
                            }
                        }
                    }

                    return(path);
                }

                else if (extension == ".7z")
                {
                    /* archive detected - extract contents to cache directory and modify path variable accordingly
                     * this is a legacy option really - in case people have a single rom in a .7z file in their library that
                     * has not been directly referenced in the gamepath */

                    // inspect the archive
                    Archive arch = new Archive(path);
                    var     res  = arch.ProcessArchive(null);

                    // iterate through
                    List <CompressionResult> resList = new List <CompressionResult>();
                    foreach (var v in res.Results)
                    {
                        if (GSystem.IsFileAllowed(v.RomName, SystemId))
                        {
                            resList.Add(v);
                        }
                    }

                    if (resList.Count == 0)
                    {
                        return(path);
                    }

                    // there should only be one result - take the first one
                    var resFinal = resList.FirstOrDefault();

                    // extract the rom to the cache
                    string cacheFile = Archive.ExtractFile(path, resFinal.InternalPath, cacheDir);

                    /*
                     * // check whether file already exists in cache
                     * string cacheFile = cacheDir + "\\" + resFinal.FileName;
                     * if (File.Exists(cacheFile))
                     * {
                     *  // file exists - check size
                     *  long length = new System.IO.FileInfo(cacheFile).Length;
                     *
                     *  if (length != filesize)
                     *  {
                     *      arch.ExtractArchive(cacheDir);
                     *  }
                     * }
                     * else
                     * {
                     *  // extract contents of archive to cache folder
                     *  arch.ExtractArchive(cacheDir);
                     * }
                     */

                    // return the new path to the rom
                    return(ParseSMD(cacheFile, cacheDir));
                }

                else if (extension == ".zip") //zip
                {
                    // this should be a zip file with a single rom inside - pass directly to mednafen as is (unless its an smd file)

                    using (System.IO.Compression.ZipArchive ar = System.IO.Compression.ZipFile.OpenRead(path))
                    {
                        foreach (System.IO.Compression.ZipArchiveEntry entry in ar.Entries)
                        {
                            if (entry.FullName.EndsWith(".smd", StringComparison.OrdinalIgnoreCase))
                            {
                                entry.Archive.ExtractToDirectory(cacheDir, true);
                                return(ParseSMD(Path.Combine(cacheDir, entry.FullName), cacheDir));
                            }
                        }
                    }

                    return(path);
                }
            }


            return(ParseSMD(path, cacheDir));
        }