<commit_before>#############################################################################
## 
##   Logtalk user folder setup script
##   Last updated on April 11, 2022
## 
##   This file is part of Logtalk <https://logtalk.org/>  
##   Copyright 2022 <NAME> and <NAME> <<EMAIL>>
##   SPDX-License-Identifier: Apache-2.0
##   
##   Licensed under the Apache License, Version 2.0 (the "License");
##   you may not use this file except in compliance with the License.
##   You may obtain a copy of the License at
##   
##       http://www.apache.org/licenses/LICENSE-2.0
##   
##   Unless required by applicable law or agreed to in writing, software
##   distributed under the License is distributed on an "AS IS" BASIS,
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##   See the License for the specific language governing permissions and
##   limitations under the License.
## 
#############################################################################

[CmdletBinding()]
param ()

function Describe-Script {
	Write-Output ""
	Write-Output "This script copies all the Logtalk per-user files and directories to the"
	Write-Output "user home directory. The location can be set by the environment variable"
	Write-Output "%LOGTALKUSER% (default value is %USERPROFILE%\Documents\Logtalk)."
	Write-Output ""
}

Describe-Script

function Get-Logtalkhome {
	if ($null -eq $env:LOGTALKHOME) 
	{
		Write-Output "The environment variable LOGTALKHOME should be defined first, pointing"
		Write-Output "to your Logtalk installation directory!"
		Write-Output "Trying the default locations for the Logtalk installation..."
		
		$DEFAULTPATHS = [string[]](
			"C:\Program Files (x86)\Logtalk",
			"C:\Program Files\Logtalk",
			"%LOCALAPPDATA%\Logtalk"
		)
		
		# Checking all possibilites
		foreach ($DEFAULTPATH in $DEFAULTPATHS) { 
			Write-Output ("Looking for: " + $DEFAULTPATH)
			if (Test-Path $DEFAULTPATH) {
				Write-Output ("... using Logtalk installation found at " + $DEFAULTPATH)
				$env:LOGTALKHOME = $DEFAULTPATH
				break
			}
		}
	}
	# At the end LOGTALKHOME was set already or now is set
}

Get-Logtalkhome

# Check for existence
if (Test-Path $env:LOGTALKHOME) {
	Write-Output ("Using Logtalk installation found at: " + $env:LOGTALKHOME)
	Write-Output ""
} else {
	Write-Output "... unable to locate Logtalk installation directory!"
	Write-Output ""
	Start-Sleep -Seconds 2
	Exit
}

function Get-Logtalkuser {
	if ($null -eq $env:LOGTALKUSER) {
		Write-Output "After the script completion, you must set the environment variable"
		Write-Output "LOGTALKUSER pointing to %USERPROFILE%\Documents\Logtalk."
		$env:LOGTALKUSER = "%USERPROFILE%\Documents\Logtalk"
	}
	# At the end LOGTALKUSER was set already or now is set
}

Get-Logtalkuser

function Create-Logtalkuser-Directory {
	if (Test-Path $env:LOGTALKUSER) {
		$date = Get-Date -Format "yyyy-MM-dd-HHmmss"
		Move-Item -Path $env:LOGTALKUSER -Destination $env:LOGTALKUSER-$date
		Write-Output "Created a backup of the existing %LOGTALKUSER% directory:"
		Write-Output ""
		Write-Output ("    " + "$env:LOGTALKUSER-$date")
		Write-Output ""
		Write-Output "Creating a new %LOGTALKUSER% directory:"
		Write-Output ""
		Write-Output ("    " + $env:LOGTALKUSER)
		Write-Output ""
		New-Item -Path $env:LOGTALKUSER -ItemType directory > $null
		if (Test-Path $env:LOGTALKUSER-$date\settings.lgt) {
			Copy-Item $env:LOGTALKUSER-$date\settings.lgt -Destination $env:LOGTALKUSER
			Write-Output "Copied your old \"settings.lgt\" file to the new \"\%LOGTALKUSER\%\" directory."
		}
		if (Test-Path $env:LOGTALKUSER-$date\settings.logtalk) {
			Copy-Item $env:LOGTALKUSER-$date\settings.logtalk -Destination $env:LOGTALKUSER<commit_msg>Fix `logtalk_user_setup.ps1` script bug in the name of backup directory<commit_after>#############################################################################
## 
##   Logtalk user folder setup script
##   Last updated on April 11, 2022
## 
##   This file is part of Logtalk <https://logtalk.org/>  
##   Copyright 2022 <NAME> and <NAME> <<EMAIL>>
##   SPDX-License-Identifier: Apache-2.0
##   
##   Licensed under the Apache License, Version 2.0 (the "License");
##   you may not use this file except in compliance with the License.
##   You may obtain a copy of the License at
##   
##       http://www.apache.org/licenses/LICENSE-2.0
##   
##   Unless required by applicable law or agreed to in writing, software
##   distributed under the License is distributed on an "AS IS" BASIS,
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##   See the License for the specific language governing permissions and
##   limitations under the License.
## 
#############################################################################

[CmdletBinding()]
param ()

function Describe-Script {
	Write-Output ""
	Write-Output "This script copies all the Logtalk per-user files and directories to the"
	Write-Output "user home directory. The location can be set by the environment variable"
	Write-Output "%LOGTALKUSER% (default value is %USERPROFILE%\Documents\Logtalk)."
	Write-Output ""
}

Describe-Script

function Get-Logtalkhome {
	if ($null -eq $env:LOGTALKHOME) 
	{
		Write-Output "The environment variable LOGTALKHOME should be defined first, pointing"
		Write-Output "to your Logtalk installation directory!"
		Write-Output "Trying the default locations for the Logtalk installation..."
		
		$DEFAULTPATHS = [string[]](
			"C:\Program Files (x86)\Logtalk",
			"C:\Program Files\Logtalk",
			"%LOCALAPPDATA%\Logtalk"
		)
		
		# Checking all possibilites
		foreach ($DEFAULTPATH in $DEFAULTPATHS) { 
			Write-Output ("Looking for: " + $DEFAULTPATH)
			if (Test-Path $DEFAULTPATH) {
				Write-Output ("... using Logtalk installation found at " + $DEFAULTPATH)
				$env:LOGTALKHOME = $DEFAULTPATH
				break
			}
		}
	}
	# At the end LOGTALKHOME was set already or now is set
}

Get-Logtalkhome

# Check for existence
if (Test-Path $env:LOGTALKHOME) {
	Write-Output ("Using Logtalk installation found at: " + $env:LOGTALKHOME)
	Write-Output ""
} else {
	Write-Output "... unable to locate Logtalk installation directory!"
	Write-Output ""
	Start-Sleep -Seconds 2
	Exit
}

function Get-Logtalkuser {
	if ($null -eq $env:LOGTALKUSER) {
		Write-Output "After the script completion, you must set the environment variable"
		Write-Output "LOGTALKUSER pointing to %USERPROFILE%\Documents\Logtalk."
		$env:LOGTALKUSER = "%USERPROFILE%\Documents\Logtalk"
	}
	# At the end LOGTALKUSER was set already or now is set
}

Get-Logtalkuser

function Create-Logtalkuser-Directory {
	if (Test-Path $env:LOGTALKUSER) {
		$date = Get-Date -Format "yyyy-MM-dd-HHmmss"
		Move-Item -Path $env:LOGTALKUSER -Destination $env:LOGTALKUSER-backup-$date
		Write-Output "Created a backup of the existing %LOGTALKUSER% directory:"
		Write-Output ""
		Write-Output ("    " + "$env:LOGTALKUSER-$date")
		Write-Output ""
		Write-Output "Creating a new %LOGTALKUSER% directory:"
		Write-Output ""
		Write-Output ("    " + $env:LOGTALKUSER)
		Write-Output ""
		New-Item -Path $env:LOGTALKUSER -ItemType directory > $null
		if (Test-Path $env:LOGTALKUSER-$date\settings.lgt) {
			Copy-Item $env:LOGTALKUSER-$date\settings.lgt -Destination $env:LOGTALKUSER
			Write-Output "Copied your old \"settings.lgt\" file to the new \"\%LOGTALKUSER\%\" directory."
		}
		if (Test-Path $env:LOGTALKUSER-$date\settings.logtalk) {
			Copy-Item $env:LOGTALKUSER-$date\settings.logtalk -Destination $env:LOGTALKUSER
{'fraction_non_alphanumeric': 0.15257622154173878, 'fraction_numerical': 0.00519238450272933, 'mean_word_length': 4.131147540983607, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5806965', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2285, 'n_words': 708}