1616from time import time
1717import hashlib
1818
19+ from PySide6 .QtCore import QDate , Qt
20+
1921# Versions
20- VERSION : str = "12-mar -2025"
21- VERSION_SHORT : str = "1.2.1 "
22+ VERSION : str = "25-apr -2025"
23+ VERSION_SHORT : str = "2.0 "
2224# Versions of file formats
23- FF_FILTER_VERSION = 1
25+ FF_FILTER_VERSION = 2
2426FF_SEARCH_VERSION = 2
2527FF_SETTINGS_VERSION = 1
26- FF_CACHE_VERSION = 2
28+ FF_CACHE_VERSION = 3
2729
2830# Defining folder variables and font sizes
2931USER_FOLDER = os .path .expanduser ("~" )
106108 "display_menu_bar_icon" : True ,
107109 "double_click_action" : "View file in Finder/File Explorer" }
108110
111+ DEFAULT_FILTER = {"VERSION" : FF_FILTER_VERSION ,
112+ "name" : "" , "name_contains" : "" ,
113+ "file_types" : FILE_FORMATS .keys (),
114+ "file_extension" : "" , "file_type_mode" : "predefined" ,
115+ "directory" : USER_FOLDER ,
116+ "dates" : {"m_date_from" : "2000-01-01" , "c_date_from" : "2000-01-01" ,
117+ "m_date_to" : QDate .currentDate ().toString (Qt .DateFormat .ISODate ),
118+ "c_date_to" : QDate .currentDate ().toString (Qt .DateFormat .ISODate )},
119+ "size" : {"min" : "" , "max" : "" }, "size_unit" : {"min" : "No Limit" , "max" : "No Limit" },
120+ "folder_depth" : "Unlimited" , "folder_depth_custom" : 0 ,
121+ "file_contains" : "" , "hidden_files" : False ,
122+ "files_folders" : 0 , "sorting" : 0 , "reverse_sorting" : False }
123+
109124# Color schemes
110125RED_LIGHT_THEME_COLOR = "#b1100c"
111126RED_DARK_THEME_COLOR = "#f27171"
@@ -125,14 +140,15 @@ def remove_cache():
125140
126141
127142# Convert a file path to the corresponding cache file or metadata
128- def path_to_cache_file (path , metadata = False ):
143+ def path_to_cache_file (path , depth , metadata = False ):
144+ # A -1 for the depth means unlimited depth
129145 if not metadata :
130- return os .path .join (CACHED_SEARCHES_FOLDER , path .replace (os .sep , "-" ) + " .FFCache" )
146+ return os .path .join (CACHED_SEARCHES_FOLDER , path .replace (os .sep , "-" ) + f"$ { depth } .FFCache" )
131147 # If instead ask for metadata
132148 elif metadata :
133- return os .path .join (CACHE_METADATA_FOLDER , path .replace (os .sep , "-" ) + " .FFCache" )
149+ return os .path .join (CACHE_METADATA_FOLDER , path .replace (os .sep , "-" ) + f"$ { depth } .FFCache" )
134150 else :
135- logging .fatal ("Wrong arguments used with the convert_path_to_cache_file() function in FF_Files.py" )
151+ return logging .fatal ("Wrong arguments used with the convert_path_to_cache_file() function in FF_Files.py" )
136152
137153
138154# Takes a path to a cache file and returns the path to the metadata file
@@ -172,7 +188,7 @@ def cache_test(is_launching):
172188 else :
173189 logging .debug ("Skipping deleting..." )
174190
175- if cache_settings .lower () in ("after a Week " , "after a Day " , "after two hours" ):
191+ if cache_settings .lower () in ("after a week " , "after a day " , "after two hours" ):
176192 # Looping through every file in CACHED_SEARCHES_FOLDER and getting separately stored creation tie
177193 # Iterating through all files in the cache folder
178194 for file in os .listdir (CACHED_SEARCHES_FOLDER ):
@@ -204,7 +220,10 @@ def cache_test(is_launching):
204220
205221# Function to get the File Size of a directory
206222def get_file_size (input_file : str ) -> int :
207- if os .path .isdir (input_file ):
223+ if os .path .islink (input_file ):
224+ # Specific error code
225+ return - 2
226+ elif os .path .isdir (input_file ):
208227 file_size_list_obj = 0
209228 # Gets the size if the path is a folder with recursively searching th director<
210229 for root , _dirs , files in os .walk (input_file ):
@@ -215,26 +234,23 @@ def get_file_size(input_file: str) -> int:
215234
216235 except (FileNotFoundError , ValueError ):
217236 continue
237+ return file_size_list_obj
218238 elif os .path .isfile (input_file ):
219239 try :
220- file_size_list_obj = os .path .getsize (input_file )
240+ return os .path .getsize (input_file )
221241 except (FileNotFoundError , ValueError ):
222242 return - 1
223243 else :
224- # Error code
244+ # Error
225245 return - 1
226- if os .path .islink (input_file ):
227- return - 2
228- else :
229- return file_size_list_obj
230246
231247
232248# Convert File Size to a String
233249def conv_file_size (byte_size : int , decimal_places = 2 ) -> str :
234250 if byte_size == - 1 :
235251 return "ERROR! (File does not exist or isn't valid)"
236252 elif byte_size == - 2 :
237- return "ERROR! ( File is a Link to an other File) "
253+ return "File is a Link to an other File"
238254 elif byte_size > 1000000000 :
239255 return f"{ round (byte_size / 1000000000 , decimal_places )} GB"
240256 elif byte_size > 1000000 :
@@ -285,6 +301,7 @@ def setup():
285301 remove_cache ()
286302
287303 # Checking if all settings exist and updating version numbers
304+ settings ["cache_version" ] = FF_CACHE_VERSION
288305 settings ["settings_version" ] = FF_SETTINGS_VERSION
289306 settings ["version" ] = f"{ VERSION_SHORT } [{ VERSION } ]"
290307
0 commit comments