diff --git a/scripts/image_browser.py b/scripts/image_browser.py index 43ce725..d48d1ea 100644 --- a/scripts/image_browser.py +++ b/scripts/image_browser.py @@ -621,6 +621,15 @@ def exif_update_dirs(maint_update_dirs_path_recorder, maint_update_dirs_exif_dat return maint_wait, maint_last_msg +def recreate_hash(maint_wait): + version = str(db_version) + conn, cursor = wib_db.transaction_begin() + wib_db.migrate_filehash(cursor, version) + wib_db.transaction_end(conn, cursor) + maint_last_msg = "Hashes recreated" + + return maint_wait, maint_last_msg + def reapply_ranking(path_recorder, maint_wait): dirs = {} @@ -1339,6 +1348,11 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab): maint_update_dirs_from = gr.Textbox(label="From (full path)") with gr.Column(scale=10): maint_update_dirs_to = gr.Textbox(label="to (full path)") + with gr.Row(visible=maint): + with gr.Column(scale=1): + maint_recreate_hash = gr.Button(value="Recreate hash for existing files") + with gr.Column(scale=10): + gr.HTML(visible=False) with gr.Row(visible=maint): with gr.Column(scale=1): maint_reapply_ranking = gr.Button(value="Reapply ranking after moving files") @@ -1485,6 +1499,12 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab): outputs=[maint_wait, maint_last_msg], show_progress=True ) + maint_recreate_hash.click( + fn=recreate_hash, + inputs=[maint_wait], + outputs=[maint_wait, maint_last_msg], + show_progress=True + ) maint_reapply_ranking.click( fn=reapply_ranking, inputs=[path_recorder, maint_wait], diff --git a/scripts/wib/wib_db.py b/scripts/wib/wib_db.py index 9044467..95ed62b 100644 --- a/scripts/wib/wib_db.py +++ b/scripts/wib/wib_db.py @@ -270,7 +270,8 @@ def migrate_filehash(cursor, version): if os.path.exists(file): hash = get_hash(file) cursor.execute(''' - INSERT INTO filehash (file, hash) + INSERT OR REPLACE + INTO filehash (file, hash) VALUES (?, ?) ''', (file, hash))