Skip to content

Commit eee72f3

Browse files
committed
fix reload all snippets and prevent example from being recreated with warning flag in place
1 parent 8050ee7 commit eee72f3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import getpass
88
from collections import namedtuple
99
from datetime import datetime
10+
from pathlib import Path
11+
1012
import binaryninjaui
1113
from binaryninjaui import (getMonospaceFont, UIAction, UIActionHandler, Menu, UIContext)
1214
if "qt_major_version" in binaryninjaui.__dict__ and binaryninjaui.qt_major_version == 6:
@@ -54,9 +56,11 @@
5456
try:
5557
if not os.path.exists(snippetPath):
5658
os.mkdir(snippetPath)
57-
dst_examples = os.path.join(snippetPath, "update_example_snippets.py")
58-
src_examples = os.path.join(os.path.dirname(os.path.realpath(__file__)), "update_example_snippets.py")
59-
if not os.path.exists(dst_examples):
59+
example_name = "update_example_snippets.py"
60+
dst_examples = os.path.join(snippetPath, example_name)
61+
rm_dst_examples = os.path.join(snippetPath, "." + example_name)
62+
src_examples = os.path.join(os.path.dirname(os.path.realpath(__file__)), example_name)
63+
if not os.path.exists(rm_dst_examples) and not os.path.exists(dst_examples):
6064
shutil.copy(src_examples, dst_examples)
6165
except IOError:
6266
log_error("Unable to create %s or unable to add example updater, please report this bug" % snippetPath)
@@ -488,6 +492,10 @@ def deleteSnippet(self):
488492
if (question == QMessageBox.StandardButton.Yes):
489493
log_debug("Snippets: Deleting snippet %s." % snippetName)
490494
self.clearSelection()
495+
if snippetName == example_name:
496+
question = QMessageBox.question(self, self.tr("Confirm"), self.tr("Should snippets prevent this file from being recreated?"))
497+
if (question == QMessageBox.StandardButton.Yes):
498+
Path(rm_dst_examples).touch()
491499
self.files.remove(selection)
492500
self.registerAllSnippets()
493501

@@ -692,6 +700,9 @@ def clearHotkey(self):
692700

693701
snippets = None
694702

703+
def reloadActions(context):
704+
Snippets.registerAllSnippets()
705+
695706
def launchPlugin(context):
696707
global snippets
697708
if not snippets:
@@ -708,6 +719,6 @@ def launchPlugin(context):
708719
UIAction.registerAction("Snippets\\Snippet Editor...")
709720
UIAction.registerAction("Snippets\\Reload All Snippets")
710721
UIActionHandler.globalActions().bindAction("Snippets\\Snippet Editor...", UIAction(launchPlugin))
711-
UIActionHandler.globalActions().bindAction("Snippets\\Reload All Snippets", UIAction(Snippets.registerAllSnippets))
722+
UIActionHandler.globalActions().bindAction("Snippets\\Reload All Snippets", UIAction(reloadActions))
712723
Menu.mainMenu("Tools").addAction("Snippets\\Snippet Editor...", "Snippet")
713724
Menu.mainMenu("Tools").addAction("Snippets\\Reload All Snippets", "Snippet")

0 commit comments

Comments
 (0)