forked from Support/sp-hydra-veil-gui
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
from PyQt6.QtWidgets import QApplication, QFileDialog
|
|
|
|
def move_database_file(original_filepath: str) -> bool:
|
|
"""
|
|
Prompts the user to select a destination for a .db file and moves it there.
|
|
|
|
Args:
|
|
original_filepath: The current path to the .db file
|
|
|
|
Returns:
|
|
True if the move was successful, False otherwise
|
|
"""
|
|
# Create a QApplication if one doesn't already exist
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication(sys.argv)
|
|
|
|
# Validate that the original file exists
|
|
if not Path(original_filepath).exists():
|
|
print(f"Error: File not found at {original_filepath}")
|
|
return False
|
|
|
|
# Open the file save dialog
|
|
destination, _ = QFileDialog.getSaveFileName(
|
|
None,
|
|
"Select destination for database file",
|
|
str(Path(original_filepath).parent), # Start in the original file's directory
|
|
"Database Files (*.db);;All Files (*)"
|
|
)
|
|
|
|
# If the user cancelled the dialog
|
|
if not destination:
|
|
print("Operation cancelled by user")
|
|
return False
|
|
|
|
try:
|
|
# Move the file
|
|
shutil.move(original_filepath, destination)
|
|
print(f"File successfully moved to: {destination}")
|
|
return True
|
|
except Exception as e:
|
|
print(f"Error moving file: {e}")
|
|
return False
|
|
|
|
|
|
def launch_file_picker(original_path):
|
|
move_database_file(original_path)
|