Skip to content

Commit

Permalink
user can now use their own library path.
Browse files Browse the repository at this point in the history
A warning got added when the user starts the tool for the first time.
Database connections gets closed now when an operation is done
  • Loading branch information
Ati1707 committed Nov 15, 2024
1 parent 54292ab commit 5c3322c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Build
on:
push:
branches:
- main
- debug
- "*"
pull_request:
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# LibraryPath = C:\Users\Public\Documents\My DAZ 3D Library
# IMPORTANT:
# - Avoid using an existing library path.
# - Create a new, dedicated directory for this library.
# - Use a new, dedicated directory for the library.

LibraryPath = library

Expand Down
12 changes: 7 additions & 5 deletions content_database.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import pathlib
import sqlite3
import configparser
import threading
from helper.config_operations import get_library_path

config = configparser.ConfigParser()
config.read("config.ini")
library_path = config["PATH"]["LibraryPath"]

lock = threading.Lock()

Expand All @@ -18,6 +15,7 @@ def add_archive(archive_name, files):
cursor.executemany("INSERT INTO files (archive_id, file_name) VALUES (?, ?)",
[(archive_id, file_name) for file_name in files])
conn.commit()
conn.close()

# Function to retrieve all archives and their files
def get_archives():
Expand All @@ -31,6 +29,7 @@ def get_archives():
cursor.execute("SELECT file_name FROM files WHERE archive_id = ?", (archive_id,))
files = cursor.fetchall()
archive_list.append((archive_name, str(len(files)) + " files" ))
conn.close()
return archive_list


Expand All @@ -51,7 +50,7 @@ def delete_archive(archive_name):
# Loop through and print the files to be deleted
if files:
for file in files:
file_path = pathlib.Path(library_path).joinpath(file[0])
file_path = pathlib.Path(get_library_path()).joinpath(file[0])
if pathlib.Path(file_path).exists():
pathlib.Path(file_path).unlink()

Expand All @@ -62,6 +61,7 @@ def delete_archive(archive_name):
print(f"Archive '{archive_name}' and its files have been deleted.")
else:
print(f"Archive '{archive_name}' not found.")
conn.close()


def archive_exist(archive_name, file_list):
Expand All @@ -85,7 +85,9 @@ def archive_exist(archive_name, file_list):
for existing_archive in existing_archives:
if existing_archive[0] == archive_name:
print(f"An archive named '{archive_name}' with {file_count} files already exists.")
conn.close()
return True
conn.close()
return False

def connect_database():
Expand Down
14 changes: 14 additions & 0 deletions helper/config_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import configparser

def get_library_path():
config = _get_config_file()
return config["PATH"].get("LibraryPath").strip('\"')

def get_debug_mode():
config = _get_config_file()
return config["DEBUG"].getboolean("DebugMode")

def _get_config_file():
config = configparser.ConfigParser()
config.read("config.ini")
return config
4 changes: 3 additions & 1 deletion helper/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ def get_file_from_path(file_path):
def get_file_name_without_extension(file):
return file.rpartition(".")[0]

def create_folders():
def create_folder() -> bool:
"""Also returns a boolean to check if it's a users first time starting the tool"""
if not Path.exists(Path("database/")):
Path.mkdir(Path("database/"))
return True

def create_temp_folder():
if not Path.exists(Path("temp/")):
Expand Down
19 changes: 4 additions & 15 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys
import time
import shutil
import configparser
import re
import threading
from helper.config_operations import get_library_path, get_debug_mode

import patoolib
from patoolib.util import PatoolError
Expand All @@ -23,14 +23,8 @@ class Bcolors:
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

download_folder = 'downloads/'
temp_folder = 'temp/'

config = configparser.ConfigParser()
config.read("config.ini")
library_path = config["PATH"]["LibraryPath"]
is_debug_mode = config["DEBUG"].getboolean("DebugMode")


lock = threading.Lock()

Expand All @@ -40,11 +34,6 @@ class Bcolors:
base_path = pathlib.Path(__file__).parents
seven_zip_path = pathlib.Path(str(base_path)).joinpath( "7z\\7z.exe")

if not library_path or library_path == "example":
print(f"{Bcolors.WARNING}You need to set a asset library path in the config.ini{Bcolors.ENDC}")
print(f"{Bcolors.WARNING}Create a new folder don't use an existing folder{Bcolors.ENDC}")
print(f"{Bcolors.WARNING}This tool is not stable yet!!! Data loss can occur if you use an existing folder{Bcolors.ENDC}")
sys.exit(0)

# Define the target folders
target_folders = [
Expand Down Expand Up @@ -142,7 +131,7 @@ def traverse_directory(folder_path, current_item, is_debug_mode):
clean_folder(root)
if add_to_database(root, current_item):
return False
shutil.copytree(root, library_path, dirs_exist_ok=True)
shutil.copytree(root, get_library_path(), dirs_exist_ok=True)
return True
return False

Expand All @@ -151,10 +140,10 @@ def start_installer_gui(file_path, is_delete_archive=False):
with lock:
create_temp_folder()
clean_temp_folder()
if not extract_archive(file_path, is_debug_mode):
if not extract_archive(file_path, get_debug_mode()):
clean_temp_folder()
return
if traverse_directory(temp_folder, pathlib.Path(file_path), is_debug_mode):
if traverse_directory(temp_folder, pathlib.Path(file_path), get_debug_mode()):
print(f"{Bcolors.OKGREEN}{file_path} was successfully imported to your library{Bcolors.ENDC}")
else:
print(f"{Bcolors.WARNING}{file_path} can not be automatically imported because it doesn't have the right folder structure{Bcolors.ENDC}")
Expand Down
15 changes: 12 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from webbrowser import open
import threading
from tkinter import BooleanVar
from tkinter.constants import DISABLED

import customtkinter as ctk
from customtkinter import CTk, filedialog, CTkLabel, deactivate_automatic_dpi_awareness
from customtkinter import CTk, filedialog, CTkLabel
import pywinstyles
from content_database import get_archives, delete_archive
from installer import start_installer_gui
Expand Down Expand Up @@ -226,8 +227,6 @@ def __init__(self):
super().__init__()
self.title("Daz Content Installer")
self.geometry(center_window_to_display(self, 1100, 650, self._get_window_scaling()))
file_operations.create_folders()


# Initialize and place MyTabView
self.tab_view = MyTabView(master=self)
Expand All @@ -240,6 +239,16 @@ def __init__(self):
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)

if file_operations.create_folder():
msg = CTkMessagebox(title="Info",
message="It seems like this is your first time opening the tool!\n\n"
"You can use the default library which will be in this folder but you can also use a different path.\n",
option_1="No",
option_2="Open configuration file",
width=500, height=250)
if msg.get() == "Open configuration file":
open("config.ini")


# Run the application
app = App()
Expand Down

0 comments on commit 5c3322c

Please sign in to comment.