Kaynağa Gözat

Compression.ps1

nathan 1 yıl önce
ebeveyn
işleme
b3f9e14322
1 değiştirilmiş dosya ile 66 ekleme ve 80 silme
  1. 66
    80
      LZX-Compression-Automated.ps1

+ 66
- 80
LZX-Compression-Automated.ps1 Dosyayı Görüntüle

@@ -1,95 +1,81 @@
1
-# Prompt the user to enter the type of drive they are planning to use this on
2
-$driveType = Read-Host "Please enter the type of drive you are planning to use this on (SSD or HDD)"
1
+# Set the compression algorithm options
2
+$options = "XPRESS4K", "XPRESS8K", "XPRESS16K", "LZX"
3 3
 
4
-# Validate the drive type input
5
-if ($driveType -eq "SSD" -or $driveType -eq "HDD") {
6
-    # Proceed with the script
7
-} else {
8
-    # Display an error message and exit the script
9
-    Write-Error "Invalid drive type. Please enter either SSD or HDD."
10
-    Exit
11
-}
12
-
13
-# If the drive type is SSD, inform the user of the pros of compression
14
-if ($driveType -eq "SSD") {
15
-    Write-Host "Compressing files and folders on a solid state drive (SSD) can have some benefits, such as:"
16
-    Write-Host "- You can save some disk space by compressing files and folders that are not already compressed or optimized. This can help you store more data on your SSD or free up some space for other purposes."
17
-    Write-Host "- You can improve the performance of your SSD by reducing the amount of data that needs to be read and written. This can lower the wear and tear of your SSD and extend its lifespan. It can also reduce the power consumption and heat generation of your SSD, which can benefit your battery life and system stability."
18
-    Write-Host "- You can enhance the security of your data by making it harder for unauthorized users or programs to access or modify your files. Compression can also help you recover some data in case of corruption or deletion, as it may preserve some parts of the original file."
19
-    Write-Host "However, there are also some cons of using this script on an SSD, such as:"
20
-    Write-Host "- You may experience some CPU overhead when compressing and decompressing files, which can affect your system performance and responsiveness. This may not be noticeable on modern CPUs, but it can still have some impact on your multitasking and gaming experience."
21
-    Write-Host "- You may encounter some compatibility issues with some applications or games that do not support compressed files or folders. This can cause errors, crashes, or performance degradation. You may need to decompress some files or folders before using them with certain programs."
22
-    Write-Host "- You may lose some data quality or functionality when compressing some types of files, such as audio, video, or document files. Compression can reduce the resolution, bitrate, or features of these files, which can affect their appearance, sound, or behavior."
23
-    Write-Host "Therefore, you should weigh the pros and cons of using this script on an SSD before deciding to do so. You should also backup your important data before running the script, in case something goes wrong. You can read more about how compression works on SSDs in [this article](^3^) or this question."
24
-}
4
+# Prompt the user to choose a compression algorithm
5
+Write-Host "Please choose a compression algorithm from the following options:"
6
+Write-Host $options
7
+Write-Host ""
25 8
 
26
-# If the drive type is HDD, inform the user of the benefits of compression
27
-if ($driveType -eq "HDD") {
28
-    Write-Host "Compressing files and folders on a hard disk drive (HDD) can improve performance by reducing disk space usage, increasing data transfer speed, and reducing seek time. However, compression also increases CPU usage and may affect some applications or games. You can read more about the pros and cons of compression on HDDs in [this article](^2^)."
9
+# Loop until the user enters a valid option
10
+do {
11
+  $choice = Read-Host "Enter your choice"
12
+  if ($options -contains $choice) {
13
+    $algorithm = $choice
14
+    break
15
+  }
16
+  else {
17
+    Write-Host "Invalid choice. Please enter one of the options."
18
+    Write-Host ""
19
+  }
29 20
 }
21
+while ($true)
30 22
 
31
-# Prompt the user to enter a drive letter for compression
32
-$drive = Read-Host "Please enter a drive letter for compression (e.g. C, D, E)"
23
+# Prompt the user to enter a directory to compress
24
+Write-Host "Please enter a directory to compress. You can copy the path by shift-right clicking on the folder and selecting 'Copy as path'."
25
+Write-Host ""
33 26
 
34
-# Validate the drive letter input
35
-if ($drive -match "^[A-Z]$") {
36
-    # Append a colon to the drive letter
37
-    $drive = $drive + ":"
38
-} else {
39
-    # Display an error message and exit the script
40
-    Write-Error "Invalid drive letter. Please enter a single uppercase letter from A to Z."
41
-    Exit
27
+# Loop until the user enters a valid directory
28
+do {
29
+  $dir = Read-Host "Enter the directory"
30
+  if (Test-Path $dir) {
31
+    break
32
+  }
33
+  else {
34
+    Write-Host "Invalid directory. Please enter a valid path."
35
+    Write-Host ""
36
+  }
42 37
 }
38
+while ($true)
43 39
 
44
-# Define the file types to exclude from compression
45
-$exclude = @("*.zip", "*.mp4", "*.mp3", "*.flv", "*.jpg", "*.png", "*.gif", "*.pdf", "*.rar", "*.7z", "*.tar", "*.gz", "*.wav", "*.aac", "*.ogg", "*.mkv", "*.avi", "*.docx", "*.xlsx", "*.pptx", "*.ttf", "*.otf", "*.woff")
46
-
47
-# Get all the files and folders on the drive
48
-$items = Get-ChildItem -Path $drive -Recurse
49
-
50
-# Loop through each item and check if it is compressible
51
-foreach ($item in $items) {
52
-    # Skip the item if it is a directory or a symbolic link
53
-    if ($item.PSIsContainer -or $item.LinkType) {
54
-        continue
55
-    }
40
+# Check if the user entered multiple directories
41
+$count = ($dir -split '"').Count - 1
56 42
 
57
-    # Skip the item if it matches any of the excluded file types
58
-    $skip = $false
59
-    foreach ($ext in $exclude) {
60
-        if ($item.Name -like $ext) {
61
-            $skip = $true
62
-            break
63
-        }
64
-    }
65
-    if ($skip) {
66
-        continue
67
-    }
43
+# If the user entered multiple directories, ask them to format them correctly
44
+if ($count -gt 1) {
45
+  Write-Host "You entered multiple directories. Please remove all spaces after any `"` and add a `*` after any `\` prior to `"` for the script to continue successfully."
46
+  Write-Host "For example: `"`C:\Users\User\Documents\Assassin's Creed Valhalla\*`" `"`C:\Users\User\Documents\3DMark\*`" `"`C:\Users\User\Documents\4a games\*`""
47
+  Write-Host ""
48
+  exit
49
+}
68 50
 
69
-    # Compress the item using compact.exe with the /C, /I, /EXE:lzx and /EXCLUDE:exclude.txt options
70
-    compact /C /I /EXE:lzx /EXCLUDE:exclude.txt $item.FullName
51
+# Notify the user of the compression level
52
+switch ($algorithm) {
53
+  "XPRESS4K" { $level = "low" }
54
+  "XPRESS8K" { $level = "medium" }
55
+  "XPRESS16K" { $level = "high" }
56
+  "LZX" { $level = "max" }
71 57
 }
72 58
 
73
-# Prompt the user if they wish to undo compression in case of compatibility reasons
74
-$undo = Read-Host "Do you wish to undo compression in case of compatibility reasons? (Y/N)"
59
+Write-Host "You chose $algorithm compression, which is $level level of compression."
60
+Write-Host ""
75 61
 
76
-# Validate the undo input
77
-if ($undo -eq "Y" -or $undo -eq "N") {
78
-    # Proceed with the script
79
-} else {
80
-    # Display an error message and exit the script
81
-    Write-Error "Invalid input. Please enter either Y or N."
82
-    Exit
62
+# Exclude the windows directory and its subdirectories
63
+$exclude = "windows"
64
+Get-ChildItem $dir -Directory | ForEach-Object {
65
+  if ($_.Name -eq $exclude) {
66
+    $dir = "$dir /EXCLUDE:$_.FullName"
67
+  }
83 68
 }
84 69
 
85
-# If the user wishes to undo compression, run the command to uncompress the data
86
-if ($undo -eq "Y") {
87
-    Write-Host "Uncompressing the data. This may take some time."
88
-    compact.exe /CompactOS:never
89
-    Write-Host "The data has been uncompressed. You may need to restart your system for the changes to take effect."
90
-}
70
+# Compress the directory and its subdirectories using the chosen algorithm
71
+Write-Host "Compressing $dir using $algorithm algorithm..."
72
+compact /c /s /a /i /exe:$algorithm $dir
73
+Write-Host ""
91 74
 
92
-# If the user does not wish to undo compression, display a message and exit the script
93
-if ($undo -eq "N") {
94
-    Write-Host "The data has been compressed. You may need to restart your system for the changes to take effect."
95
-}
75
+# Display the compression results
76
+Write-Host "Compression completed. Here are the results:"
77
+compact /q $dir
78
+Write-Host ""
79
+
80
+# End the script
81
+pause

Powered by TurnKey Linux.