Jump to content

How to tell is the file was changed by REPLACE_TEXTUALLY


Magus

Recommended Posts

I have the following approximate code

COPY_EXISTING_REGEXP GLOB ~^.+\.bcs$~ ~override~
  changed1 = 0
  changed2 = 0

  DECOMPILE_AND_PATCH BEGIN
    REPLACE_TEXTUALLY ~a~ ~b~
    PATCH_IF (...) BEGIN changed1 = 1 END
  END
  PATCH_IF changed1 = 1 BEGIN
    PATCH_PRINT ~file %SOURCE_FILE% was changed by patch1~
  END

  DECOMPILE_AND_PATCH BEGIN
    REPLACE_TEXTUALLY ~c~ ~d~
    PATCH_IF (...) BEGIN changed2 = 1 END
  END
  PATCH_IF changed2 = 1 BEGIN
    PATCH_PRINT ~file %SOURCE_FILE% was changed by patch2~
  END

BUT_ONLY

How would I detect the change to set the corresponding vars?

Link to comment

If you just want to tell if the file is changed, use FILE_MD5.

 

99% of the time, you should be able to check for the specific thing you're changing, though. e.g. in your actual examples, use INDEX_BUFFER to see if there are any occurrences of the swapped character.

Link to comment

either REPLACE_EVALUATE or use code like this:

COUNT_REGEXP_INSTANCES ~text~ num_matches
PATCH_IF num_matches > 0 BEGIN
  REPLACE_TEXTUALLY ~test~ ~replacedText~
END ELSE BEGIN
  //do something if text for replace is not present, for example use PATCH_WARN
END
Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...