Skip to content

Commit

Permalink
Merge pull request #6 from Eryoneta/develop
Browse files Browse the repository at this point in the history
Implementação de Cores
  • Loading branch information
Eryoneta authored Nov 17, 2023
2 parents b770190 + e8d1e41 commit ba146c4
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 36 deletions.
23 changes: 18 additions & 5 deletions Functions/FileManager.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Function DeleteFilesList($modifiedFilesMap, $filesToDelete, $listOnly) {
# Da lista, deleta arquivos
ForEach($fileToDelete In $filesToDelete) {
# Deleta arquivo
PrintText ("`tDeleted`t" + $fileToDelete.Path);
PrintText "`tDeleted`t" -FC "DarkCyan" -N;
PrintText "$($fileToDelete.Path)" -FC "White";
If(-Not $listOnly) {
$Null = (Remove-Item -LiteralPath $fileToDelete.Path -Recurse -Force);
}
Expand Down Expand Up @@ -35,7 +36,10 @@ Function RenameRemovedFilesList($modifiedFilesMap, $filesToRename, $listOnly) {
}
$remotion = (" " + $remotionStart + $newRemotionCountdown + $remotionEnd);
$newName = ($fileToRename.BaseName + $version + $remotion + $fileToRename.Extension);
PrintText ("`tRenamed`t" + $fileToRename.Path + " ---> " + $newName);
PrintText "`tRenamed`t" -FC "DarkCyan" -N;
PrintText "$($fileToRename.Path)" -FC "White" -N;
PrintText " ---> " -FC "DarkCyan" -N;
PrintText "$newName" -FC "White";
If(-Not $listOnly) {
$Null = (Rename-Item -LiteralPath $fileToRename.Path -NewName $newName -Force);
}
Expand Down Expand Up @@ -67,7 +71,10 @@ Function RenameVersionedFilesList($modifiedFilesMap, $filesToRename, $listOnly)
$remotion = (" " + $remotionStart + $fileToRename.RemotionCountdown + $remotionEnd);
}
$newName = ($fileToRename.BaseName + $version + $remotion + $fileToRename.Extension);
PrintText ("`tRenamed`t" + $fileToRename.Path + " ---> " + $newName);
PrintText "`tRenamed`t" -FC "DarkCyan" -N;
PrintText "$($fileToRename.Path)" -FC "White" -N;
PrintText " ---> " -FC "DarkCyan" -N;
PrintText "$newName" -FC "White";
If(-Not $listOnly) {
$Null = (Rename-Item -LiteralPath $fileToRename.Path -NewName $newName -Force);
}
Expand Down Expand Up @@ -101,7 +108,10 @@ Function CopyVersionedFilesList($modifiedFilesMap, $filesToCopy, $listOnly) {
$fileBasePath = (Split-Path -Path $fileToCopy.Path -Parent);
$newName = ($fileToCopy.BaseName + $version + $remotion + $fileToCopy.Extension);
$newPath = (Join-Path -Path $fileBasePath -ChildPath $newName);
PrintText ("`tCopied`t" + $fileToCopy.Path + " ---> " + $newPath);
PrintText "`tCopied`t" -FC "DarkCyan" -N;
PrintText "$($fileToCopy.Path)" -FC "White" -N;
PrintText " ---> " -FC "DarkCyan" -N;
PrintText "$newPath" -FC "White";
If(-Not $listOnly) {
$Null = (Copy-Item -LiteralPath $fileToCopy.Path -Destination $newPath -Force);
}
Expand Down Expand Up @@ -138,7 +148,10 @@ Function CopyRemovedFilesList($modifiedFilesMap, $filesToCopy, $listOnly) {
$fileBasePath = (Split-Path -Path $fileToCopy.Path -Parent);
$newName = ($fileToCopy.BaseName + $version + $remotion + $fileToCopy.Extension);
$newPath = (Join-Path -Path $fileBasePath -ChildPath $newName);
PrintText ("`tCopied`t" + $fileToCopy.Path + " ---> " + $newPath);
PrintText "`tCopied`t" -FC "DarkCyan" -N;
PrintText "$($fileToCopy.Path)" -FC "White" -N;
PrintText " ---> " -FC "DarkCyan" -N;
PrintText "$newPath" -FC "White";
If(-Not $listOnly) {
If($isFolder) {
$Null = (Copy-Item -LiteralPath $fileToCopy.Path -Destination $newPath -Force);
Expand Down
25 changes: 23 additions & 2 deletions Functions/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,29 @@ $wildcardOfRemovedFile = ("*" + $remotionStart + "*" + $remotionEnd + "*");
$wildcardOfRemovedFolder = ("*" + $remotionFolder + "*");

# Print sem interromper o fluxo
Function PrintText($text) {
Write-Information -MessageData ($text) -InformationAction Continue;
Function PrintText {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True, Position = 0)]
[Alias("M")]
[Object] $MessageData = "",
[Parameter()]
[Alias("FC")]
[ConsoleColor] $ForegroundColor = $Host.UI.RawUI.ForegroundColor,
[Parameter()]
[Alias("BC")]
[ConsoleColor] $BackgroundColor = $Host.UI.RawUI.BackgroundColor,
[Parameter()]
[Alias("N")]
[Switch] $NoNewline = $False
)
$message = [System.Management.Automation.HostInformationMessage] @{
Message = $MessageData;
ForegroundColor = $ForegroundColor;
BackgroundColor = $BackgroundColor;
NoNewline = $NoNewline;
};
Write-Information $message -InformationAction "Continue";
}

# Retorna um fileMap de arquivos modificados no $destPath
Expand Down
4 changes: 2 additions & 2 deletions Functions/Mirror.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Realiza a cópia
Function Mirror($origPath, $destPath, $toModify, $listOnly) {
If(-Not $toModify) {
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
# Return; # Retirado por precaução. Mesmo que Robocopy não fazer nada, o executar
}
$list = "";
Expand All @@ -15,5 +15,5 @@ Function Mirror($origPath, $destPath, $toModify, $listOnly) {
/XD `
$wildcardOfRemovedFolder `
$list /NJH /NJS /NDL;
PrintText ("");
PrintText "";
}
2 changes: 1 addition & 1 deletion Functions/UpdateRemoved.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Function UpdateRemoved($modifiedFilesMap, $removedFoldersList, $remotionCountdow
}
# Output
If($filesToDelete.Count -eq 0 -And $filesToRename.Count -eq 0) {
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
}
# Da lista, deleta arquivos
DeleteFilesList $modifiedFilesMap $filesToDelete $listOnly;
Expand Down
4 changes: 2 additions & 2 deletions Functions/UpdateToRemove.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Function UpdateToRemove($modifiedFilesMap, $toRemoveList, $toRemoveFolderList, $remotionCountdown, $listOnly) {
If($remotionCountdown -eq 0) {
# Com 0, não deve fazer nada
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
Return $modifiedFilesMap;
}
$filesToDelete = [System.Collections.ArrayList]::new();
Expand Down Expand Up @@ -42,7 +42,7 @@ Function UpdateToRemove($modifiedFilesMap, $toRemoveList, $toRemoveFolderList, $
}
# Output
If($filesToDelete.Count -eq 0 -And $filesToRename.Count -eq 0 -And $filesToCopy.Count -eq 0) {
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
}
# Da lista, deleta arquivos
DeleteFilesList $modifiedFilesMap $filesToDelete $listOnly;
Expand Down
4 changes: 2 additions & 2 deletions Functions/UpdateToVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Function UpdateToVersion($modifiedFilesMap, $toVersionList, $maxVersionLimit, $listOnly) {
If($maxVersionLimit -eq 0) {
# Com 0, não deve fazer nada
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
Return $modifiedFilesMap;
}
$filesToDelete = [System.Collections.ArrayList]::new();
Expand All @@ -20,7 +20,7 @@ Function UpdateToVersion($modifiedFilesMap, $toVersionList, $maxVersionLimit, $l
}
# Output
If($filesToDelete.Count -eq 0 -And $filesToRename.Count -eq 0 -And $filesToCopy.Count -eq 0) {
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
}
# Da lista, deleta arquivos
DeleteFilesList $modifiedFilesMap $filesToDelete $listOnly;
Expand Down
4 changes: 2 additions & 2 deletions Functions/UpdateVersioned.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Function UpdateVersioned($modifiedFilesMap, $maxVersionLimit, $destructive, $listOnly) {
# Não-Destrutivo = Não faz nada
If(-Not $destructive) {
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
Return $modifiedFilesMap;
}
# Destrutivo = Aplica $maxVersionLimit, listando arquivos para renomear ou deletar
Expand Down Expand Up @@ -48,7 +48,7 @@ Function UpdateVersioned($modifiedFilesMap, $maxVersionLimit, $destructive, $lis
}
# Output
If($filesToDelete.Count -eq 0 -And $filesToRename.Count -eq 0) {
PrintText ("`tNenhuma ação necessária");
PrintText "`tNenhuma ação necessária" -FC "DarkCyan";
}
# Da lista, deleta arquivos
DeleteFilesList $modifiedFilesMap $filesToDelete $listOnly;
Expand Down
49 changes: 29 additions & 20 deletions RoboVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,51 @@ Function RoboVersion {
. (Join-Path -Path $PSScriptRoot -ChildPath "\Functions\UpdateToVersion.ps1");
. (Join-Path -Path $PSScriptRoot -ChildPath "\Functions\UpdateToRemove.ps1");
. (Join-Path -Path $PSScriptRoot -ChildPath "\Functions\Mirror.ps1");
PrintText ("");
PrintText ("");
PrintText ("RoboVersion: " + $OrigPath + " ---> " + $DestPath);
PrintText ("");
PrintText "";
PrintText "";
PrintText "RoboVersion: " -FC "DarkBlue" -N;
PrintText "$OrigPath" -FC "White" -N;
PrintText " ---> " -FC "DarkCyan" -N;
PrintText "$DestPath" -FC "White";
PrintText "";
# Lista os arquivos versionados e removidos
PrintText ("Escaneando por versionados e removidos...");
PrintText "Escaneando por versionados e removidos..." -FC "DarkCyan";
$modifiedLists = (GetModifiedFilesMap $DestPath);
$modifiedFilesMap = $modifiedLists.ModifiedFilesMap;
$removedFoldersList = $modifiedLists.RemovedFoldersList;
PrintText ("");
PrintText "";
# Atualiza os arquivos versionados e removidos em $DestPath
PrintText ("Etapa 1: Tratar arquivos versionados no destino");
PrintText "Etapa 1: " -FC "DarkBlue" -N;
PrintText "Tratar arquivos versionados no destino" -FC "DarkCyan";
$modifiedFilesMap = (UpdateVersioned $modifiedFilesMap $VersionLimit $Destructive $ListOnly);
PrintText ("");
PrintText ("Etapa 2: Tratar arquivos removidos no destino");
PrintText "";
PrintText "Etapa 2: " -FC "DarkBlue" -N;
PrintText "Tratar arquivos removidos no destino" -FC "DarkCyan";
$modifiedFilesMap = (UpdateRemoved $modifiedFilesMap $removedFoldersList $RemotionCountdown $Destructive $ListOnly);
PrintText ("");
PrintText "";
# Lista os arquivos a versionar ou remover
PrintText ("Escaneando por arquivos a serem modificados ou deletados...");
PrintText "Escaneando por arquivos a serem modificados ou deletados..." -FC "DarkCyan";
$willModifyLists = (GetWillModifyFilesMap $OrigPath $DestPath);
$toModify = $willModifyLists.WillModify;
$toVersionList = $willModifyLists.WillModifyList;
$toRemoveList = $willModifyLists.WillDeleteList;
$toRemoveFolderList = $willModifyLists.WillDeleteFolderList;
PrintText ("");
PrintText "";
# Atualiza os arquivos a versionar ou remover em $DestPath
PrintText ("Etapa 3: Criar versões de arquivos modificados na origem");
PrintText "Etapa 3: " -FC "DarkBlue" -N;
PrintText "Criar versões de arquivos modificados na origem" -FC "DarkCyan";
$modifiedFilesMap = (UpdateToVersion $modifiedFilesMap $toVersionList $VersionLimit $ListOnly);
PrintText ("");
PrintText ("Etapa 4: Criar remoções de arquivos deletados na origem");
PrintText "";
PrintText "Etapa 4: " -FC "DarkBlue" -N;
PrintText "Criar remoções de arquivos deletados na origem" -FC "DarkCyan";
$modifiedFilesMap = (UpdateToRemove $modifiedFilesMap $toRemoveList $toRemoveFolderList $RemotionCountdown $ListOnly);
PrintText ("");
PrintText ("Etapa 5: Iniciar Robocopy e realizar espelhamento");
PrintText "";
PrintText "Etapa 5: " -FC "DarkBlue" -N;
PrintText "Iniciar Robocopy e realizar espelhamento" -FC "DarkCyan";
# Realiza a cópia
Mirror $OrigPath $DestPath $toModify $ListOnly;
PrintText ("");
PrintText ("RoboVersion: Concluído");
PrintText ("");
PrintText "";
PrintText "RoboVersion: " -FC "DarkBlue" -N;
PrintText "Concluído" -FC "DarkCyan";
PrintText "";
}

0 comments on commit ba146c4

Please sign in to comment.