From 40942968ae7722379ec7c307384033056c5e8fd1 Mon Sep 17 00:00:00 2001 From: Olai Date: Wed, 29 May 2024 10:51:40 +0200 Subject: [PATCH] Feature: Added fileFormat Added the opportunity to change the format of the log file, this is not the name. but the format. .log .txt etc --- Chrome Downloader.ps1 | 9 +++++++-- README.md | 8 +++++--- Rename.ps1 | 8 +++++++- config.json | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Chrome Downloader.ps1 b/Chrome Downloader.ps1 index 5d5e12a..8841774 100644 --- a/Chrome Downloader.ps1 +++ b/Chrome Downloader.ps1 @@ -11,15 +11,20 @@ if (-not $dateFormat) { # Function to log messages with the specified date format $logFileName = $config.logging.fileName +$logFileFormat = $config.logging.fileFormat if (-not $logFileName) { - $logFileName = "chrome_downloader.log" + $logFileName = "chrome_downloader" } +if (-not $logFileFormat) { + $logFileFormat = "log" +} +$logFileNameFormat = $logFileName+"."+$logFileFormat function Log-Message { param ( [string]$message ) $timestamp = Get-Date -Format $dateFormat - Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileName" -Encoding utf8 + Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileNameFormat" -Encoding utf8 } # Log the start of the script diff --git a/README.md b/README.md index b8e61bb..88a0e9d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ The `config.json` file should be structured as follows: "checkExist": false }, "logging": { - "fileName": "chrome_downloader.log", + "fileName": "chrome_downloader", + "fileFormat": "log", "logDateFormat": "dd/MM/yyyy HH:mm:ss" } @@ -30,7 +31,8 @@ The `config.json` file should be structured as follows: - `enableForcedVersion`: A boolean flag to enable downloading and installing the forced update version of Chrome. - `folderNumberedVersion`: A boolean flag to enable the automatic renaming of the folder to the newest version of Chrome. ⚠️ **This option requires administrative privileges when executing the script!** ⚠️ - `checkExist`: A boolean flag to delete old Chrome folders when the script is executed. ⚠️ **This action will delete your Chrome folders, so ensure you have backups if you wish to retain them.** ⚠️ -- `fileName`: A string defining the name of the log file. The default format is `chrome_downloader.log`. +- `fileName`: A string defining the name of the log file. The default name is `chrome_downloader`. +- `fileFormat`: A string defining the format of the log file. The default format is `log`. - `logDateFormat`: A string defining the format of timestamps in logs. The default format is `dd/MM/yyyy HH:mm:ss`. @@ -110,7 +112,7 @@ You can download the script using `git clone` command. Follow these steps: 2. Navigate to the directory where you want to download the script. 3. Run the following command: ``` -git clone https://github.com/OlaYZen/Chrome-Downloader.git +git clone https://forgejo.olayzen.com/OlaYZen/Chrome-Downloader.git ``` This command will clone the repository into your current directory. diff --git a/Rename.ps1 b/Rename.ps1 index 46c9510..323a257 100644 --- a/Rename.ps1 +++ b/Rename.ps1 @@ -13,15 +13,21 @@ $forceUpdateFolder = Join-Path -Path $PSScriptRoot -ChildPath "Chrome - VERSION_ # Function to log messages with the specified date format $logFileName = $config.logging.fileName +$logFileFormat = $config.logging.fileFormat if (-not $logFileName) { $logFileName = "chrome_downloader.log" } +if (-not $logFileFormat) { + $logFileFormat = "log" +} +$logFileNameFormat = $logFileName+"."+$logFileFormat + function Log-Message { param ( [string]$message ) $timestamp = Get-Date -Format $dateFormat - Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileName" -Encoding utf8 + Write-Output "[$timestamp] - $message" | Out-File -Append -FilePath "$PSScriptRoot\$logFileNameFormat" -Encoding utf8 } if ($config.options.enableRegularVersion -and -not $config.options.enableForcedVersion) { diff --git a/config.json b/config.json index 39b0c9b..0304a43 100644 --- a/config.json +++ b/config.json @@ -6,7 +6,8 @@ "checkExist": false }, "logging": { - "fileName": "chrome_downloader.log", + "fileName": "chrome_downloader", + "fileFormat": "log", "logDateFormat": "dd/MM/yyyy HH:mm:ss" } } \ No newline at end of file