Example #1
0
        private void btnMove_Click(object sender, EventArgs e)
        {
            long newOffset = 0U;

            if (long.TryParse(txtAddress.Text, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out newOffset))
            {
                DataGridViewSelectedRowCollection selectedRows = dgv_FreeSpace.SelectedRows;
                if (selectedRows.Count > 0)
                {
                    DataGridViewRow row    = selectedRows[0];
                    long            offset = (long)(row.Cells[1].Value);

                    if (offset != newOffset)
                    {
                        PatchedByteArray patchedByteArray = rowPatchMap[row];
                        AsmPatch         asmPatch         = freeSpaceMaps.InnerPatchMap[patchedByteArray];
                        long             moveOffset       = newOffset - offset;

                        MovePatchRange movePatchRange = new MovePatchRange(new PatchRange(patchedByteArray), moveOffset);
                        asmPatch.MoveBlock(asmUtility, movePatchRange);
                        asmPatch.Update(asmUtility);

                        txtAddress.BackColor = Color.White;
                        Reload();
                    }
                }
            }
            else
            {
                txtAddress.BackColor = Color.FromArgb(225, 125, 125);
            }
        }
Example #2
0
 public void MoveBlock(ASMEncoding.ASMEncodingUtility utility, MovePatchRange movePatchRange)
 {
     MoveBlocks(utility, new MovePatchRange[1] {
         movePatchRange
     });
 }
        public static ConflictResolveResult ResolveConflicts(IList <AsmPatch> patchList, ASMEncoding.ASMEncodingUtility asmUtility, int maxConflictResolveAttempts = MaxConflictResolveAttempts)
        {
            List <AsmPatch>            resultPatchList = new List <AsmPatch>();
            Dictionary <AsmPatch, int> patchIndexMap   = new Dictionary <AsmPatch, int>();
            StringBuilder sbMessage    = new StringBuilder();
            bool          hasConflicts = false;

            for (int index = 0; index < patchList.Count; index++)
            {
                resultPatchList.Add(patchList[index]);
                patchIndexMap.Add(patchList[index], index);
            }

            Context       context       = (asmUtility.EncodingMode == ASMEncoding.ASMEncodingMode.PSP) ? Context.US_PSP : Context.US_PSX;
            FreeSpaceMode mode          = FreeSpace.GetMode(context);
            FreeSpaceMaps freeSpaceMaps = FreeSpace.GetFreeSpaceMaps(resultPatchList, mode);

            foreach (PatchRange freeSpaceRange in freeSpaceMaps.PatchRangeMap.Keys)
            {
                List <PatchedByteArray> innerPatches  = freeSpaceMaps.PatchRangeMap[freeSpaceRange];
                FreeSpaceAnalyzeResult  analyzeResult = FreeSpace.Analyze(innerPatches, freeSpaceRange, true);
                int conflictResolveAttempts           = 0;

                /*
                 * Type sectorType = ISOHelper.GetSectorType(context);
                 * Enum sector = (Enum)Enum.ToObject(sectorType, freeSpaceRange.Sector);
                 * string strSector = (mode == FreeSpaceMode.PSP) ? PspIso.GetSectorName((PspIso.Sectors)sector) : PsxIso.GetSectorName((PsxIso.Sectors)sector);
                 */

                string strSector = ISOHelper.GetSectorName(freeSpaceRange.Sector, context);

                while ((analyzeResult.HasConflicts) && (conflictResolveAttempts < maxConflictResolveAttempts))
                {
                    bool isStatic   = false;
                    bool stayStatic = false;

                    int endIndex = innerPatches.Count - 1;
                    for (int index = 0; index < endIndex; index++)
                    {
                        PatchedByteArray innerPatch = innerPatches[index];
                        isStatic   = innerPatch.IsStatic || stayStatic;
                        stayStatic = (innerPatch.IsStatic) && (innerPatch.IsPatchEqual(innerPatches[index + 1]));

                        if ((analyzeResult.ConflictIndexes.Contains(index)) && (!isStatic))
                        {
                            long           moveOffset     = analyzeResult.LargestGapOffset - innerPatch.Offset;
                            MovePatchRange movePatchRange = new MovePatchRange(new PatchRange(innerPatch), moveOffset);

                            AsmPatch asmPatch         = freeSpaceMaps.InnerPatchMap[innerPatch];
                            int      resultPatchIndex = patchIndexMap[asmPatch];
                            patchIndexMap.Remove(asmPatch);

                            asmPatch = asmPatch.Copy();
                            resultPatchList[resultPatchIndex] = asmPatch;
                            patchIndexMap.Add(asmPatch, resultPatchIndex);
                            asmPatch.MoveBlock(asmUtility, movePatchRange);
                            asmPatch.Update(asmUtility);

                            sbMessage.AppendLine("Conflict resolved by moving segment of patch \"" + asmPatch.Name + "\" in sector " + strSector + " from offset "
                                                 + innerPatch.Offset.ToString("X") + " to " + analyzeResult.LargestGapOffset.ToString("X") + ".");

                            freeSpaceMaps = FreeSpace.GetFreeSpaceMaps(resultPatchList, mode);
                            innerPatches  = freeSpaceMaps.PatchRangeMap[freeSpaceRange];
                            analyzeResult = FreeSpace.Analyze(innerPatches, freeSpaceRange, false);
                            conflictResolveAttempts++;
                            break;
                        }
                    }
                }

                if (analyzeResult.HasConflicts)
                {
                    hasConflicts = true;
                    int endIndex = innerPatches.Count - 1;
                    for (int index = 0; index < endIndex; index++)
                    {
                        if (analyzeResult.ConflictIndexes.Contains(index))
                        {
                            sbMessage.Length = 0;
                            sbMessage.AppendLine("Conflict in sector " + strSector + " at offset " + innerPatches[index].Offset.ToString("X") + "!");
                            break;
                        }
                    }
                }
            }

            return(new ConflictResolveResult(resultPatchList, hasConflicts, sbMessage.ToString()));
        }