The Folder Opener is a C program designed to open folders specified in a text file. It supports multiple languages and provides verbose/silent modes for controlling output. It handles Windows, Linux, and macOS.
folder_opener.c: The main source file containing the code.folder_opener.languages: The file storing language-specific messages.folder_opener.folders: The file containing the list of folders to open.
- Standard C libraries:
stdio.h,stdlib.h,string.h,sys/stat.h - Platform-specific headers:
- Windows:
windows.h,shellapi.h - Unix-like:
unistd.h
- Windows:
- Purpose: A custom implementation of
getlinefor reading lines from a file. - Logic:
- Allocates or resizes the line buffer.
- Reads characters until EOF or newline is encountered.
- Returns the length of the line read or -1 on error.
- Purpose: Load language messages from a file based on the specified language ID.
- Logic:
- Reads the language file line-by-line.
- Checks if the current language ID matches the target.
- Parses messages marked with
$message1,$message2, etc. - Stores messages in a global
messagesarray. - Returns 0 if all messages are loaded, otherwise returns 1.
- Purpose: Check if a specified folder exists.
- Logic:
- Uses
statto retrieve file information. - Returns true if the path exists and is a directory.
- Uses
- Purpose: Validates the input to prevent command injection.
- Logic:
- Checks for special characters (
&,?,*, etc.) in the input. - Returns true if any unsafe character is found.
- Checks for special characters (
- Purpose: Open the specified folder.
- Logic:
- Validates input using
sanitize_input. - Checks if the folder exists using
folder_exists. - Depending on the platform:
- Windows: Uses
ShellExecuteEx. - macOS: Uses
/usr/bin/open. - Linux: Uses
xdg-open.
- Windows: Uses
- Prints appropriate error messages using loaded language strings.
- Validates input using
- Purpose: Entry point of the program.
- Logic:
- Sets UTF-8 output on Windows.
- Parses command-line arguments for language and verbosity.
- Loads language messages.
- Checks other command-line options, printing unknown options.
- Reads the folders file line-by-line.
- Opens each folder by calling
open_folder. - Frees allocated message memory.
Compile the code using a C compiler. Example for GCC:
gcc -o folder_opener folder_opener.cRun the program specifying the language:
./folder_opener -language HROr, if no language is specified, it defaults to English.