Esempio n. 1
0
        /// <summary>
        /// Assigns a fork.
        /// </summary>
        /// <param name="kind">The kind of fork to assign.</param>
        /// <param name="fork">The actual fork to assign.</param>
        protected void SetFork(ForkKind kind, Fork fork)
        {
            switch (kind)
            {
            case ForkKind.NumberOfForkKinds:
            case ForkKind.None:
                break;

            default:
                var previousFork = _forks[(int)kind];
                _forks[(int)kind] = fork;
                if (previousFork != null)
                {
#if DEBUG_ENTRY_REMOVAL
                    var activityBuilder = new System.Text.StringBuilder();
                    var oldForkString   = (previousFork == null) ? "<null>" : previousFork.ToString();
                    var newForkString   = (fork == null) ? "<null>" : fork.ToString();
                    activityBuilder.AppendLine("Removing fork from file system in SetForks:");
                    activityBuilder.AppendFormat("  old: {0}", oldForkString).AppendLine();
                    activityBuilder.AppendFormat("  new: {0}", newForkString).AppendLine();
                    if (fork == null)
                    {
                        activityBuilder.AppendLine("  Stack Trace when setting to null:");
                        activityBuilder.Append(System.Environment.StackTrace);
                    }
                    FileSystem.Forks.LogActivity(activityBuilder.ToString());
#endif // DEBUG_ENTRY_REMOVAL
                    FileSystem.Forks.Remove(previousFork);
                }
                break;
            }
        }
Esempio n. 2
0
        private Fork GetFork(ForkKind which)
        {
            Fork fork             = null;
            var  globalForkNumber = _forks[(int)which];

            if (globalForkNumber < GlobalForkTable.TableSize)
            {
                fork = FileSystem.Forks[globalForkNumber];
            }
            return(fork);
        }
Esempio n. 3
0
        private void UpdateFork(ForkKind kind, string filePath)
        {
            Fork fork = null;

            switch (kind)
            {
            case ForkKind.Program:
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    fork = FileSystem.Forks.AddFork(Description.GetRom());
                    if (PathComparer.Instance.Compare(filePath, fork.FilePath) != 0)
                    {
                        // Hmmm.... The path changed. It's possible we got a de-dupe here. So only complain if we have zero file size or default CRC.
                        if ((fork.Size == 0) || (fork.Crc24 == INTV.Core.Utility.Crc24.InvalidCrc))
                        {
                            var forkFilePath = string.IsNullOrEmpty(fork.FilePath) ? "<null>" : fork.FilePath;
                            var description  = string.Format(Resources.Strings.RomToLuigiFailed_FilePathsDoNotMatchFormat, filePath, forkFilePath);
                            throw new LuigiFileGenerationException(Resources.Strings.RomToLuigiFailed_FilePathsDoNotMatchMessage, description);
                        }
                    }
                    if (!System.IO.File.Exists(fork.FilePath))
                    {
                        var message = string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.Strings.RomToLuigiFailed_OutputFileNotFound_Error_Format, Description.Rom.RomPath, fork.FilePath);
                        throw new LuigiFileGenerationException(message, Resources.Strings.RomToLuigiFailed_OutputFileNotFound_Error_Description_Format);
                    }
                }
                break;

            default:
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    if (System.IO.File.Exists(filePath))
                    {
                        fork = FileSystem.Forks.AddFork(filePath);
                    }
                }
                break;
            }
            SetFork(kind, fork);
        }
Esempio n. 4
0
 private void SetFork(ForkKind which, Fork fork)
 {
     _forks[(int)which] = (fork == null) ? GlobalForkTable.InvalidForkNumber : fork.GlobalForkNumber;
 }
 private static void ReportForkSyncError(Fork fork, ForkKind forkKind, ILfsFileInfo localFile, FileSystemSyncErrors syncErrors)
 {
     System.Diagnostics.Debug.WriteLine("What to do with " + forkKind + " for file number " + localFile.GlobalFileNumber + "??");
     syncErrors.UnsupportedForks.Add(new Tuple <ILfsFileInfo, Fork>(localFile, fork));
 }
        private static bool SyncForkData(Fork fork, ForkKind forkKind, Dictionary <ushort, string> forkSourceFileMap, Action <Fork, ForkKind> errorAction, ref ProgramDescription description)
        {
            var succeeded = true;

            if (fork != null)
            {
                var crc = 0u;
                switch (forkKind)
                {
                case ForkKind.Program:
                    var cfgCrc     = 0u;
                    var cacheEntry = CacheIndex.Find(fork.Crc24, fork.Size);
                    if (cacheEntry != null)
                    {
                        crc    = cacheEntry.RomCrc32;
                        cfgCrc = cacheEntry.CfgCrc32;
                    }
                    else
                    {
                        string romPath;
                        if (forkSourceFileMap.TryGetValue(fork.GlobalForkNumber, out romPath) && !string.IsNullOrEmpty(romPath) && System.IO.File.Exists(romPath))
                        {
                            if (LuigiFileHeader.PotentialLuigiFile(romPath))
                            {
                                var luigiHeader = LuigiFileHeader.GetHeader(romPath);
                                if (luigiHeader.Version > 0)
                                {
                                    crc    = luigiHeader.OriginalRomCrc32;
                                    cfgCrc = luigiHeader.OriginalCfgCrc32;
                                }
                            }
                            if (crc == 0u)
                            {
                                crc = Crc32.OfFile(romPath);
                            }
                        }
                        else
                        {
                            System.Console.WriteLine("SDFS");
                        }
                    }
                    if (crc != 0)
                    {
                        var romListDescriptions = INTV.Shared.Model.Program.ProgramCollection.Roms.Where(d => d.Crc == crc);
                        if (romListDescriptions.Any())
                        {
                            var romListDescription = romListDescriptions.FirstOrDefault(d => (d.Rom != null) && (d.Rom.CfgCrc == cfgCrc));
                            if (romListDescription != null)
                            {
                                description = romListDescription.Copy();
                            }
                        }
                    }
                    if (description == null)
                    {
                        var rom = fork.Rom;
                        if (rom == null)
                        {
                            string romPath;
                            succeeded = forkSourceFileMap.TryGetValue(fork.GlobalForkNumber, out romPath);
                            if (succeeded)
                            {
                                rom      = Rom.Create(romPath, null);
                                fork.Rom = rom;
                                if (string.IsNullOrEmpty(fork.FilePath))
                                {
                                    fork.FilePath = romPath;
                                }
                            }
                        }
                        if (rom != null)
                        {
                            var programInfo = rom.GetProgramInformation();
                            description = new ProgramDescription(rom.Crc, rom, programInfo);
                        }
                    }
                    break;

                case ForkKind.Manual:
                    string filePath;
                    if (forkSourceFileMap.TryGetValue(fork.GlobalForkNumber, out filePath) && System.IO.File.Exists(filePath))
                    {
                        fork.FilePath = filePath;
                        if (description != null)
                        {
                            description.Files.DefaultManualTextPath = fork.FilePath;
                        }
                    }
                    break;

                case ForkKind.JlpFlash:
                    // TODO / FIXME : We don't do anything with JLP save data forks when syncing from the file system.
                    break;

                case ForkKind.Vignette:
                case ForkKind.Reserved4:
                case ForkKind.Reserved5:
                case ForkKind.Reserved6:
                    succeeded = false;
                    break;
                }
            }
            if (!succeeded && (errorAction != null))
            {
                errorAction(fork, forkKind);
            }
            return(succeeded);
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of of the UnsupportedForkKindException class.
 /// </summary>
 /// <param name="forkKind">The unsupported fork.</param>
 public UnsupportedForkKindException(ForkKind forkKind)
     : base(string.Format(Resources.Strings.UnsupportedForkKindException_MessageFormat, forkKind))
 {
     ForkKind = forkKind;
 }