-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinflux.py
More file actions
181 lines (135 loc) · 5.6 KB
/
winflux.py
File metadata and controls
181 lines (135 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python3
"""
WinFlux - Windows System Optimizer
A powerful CLI tool for cleaning, optimizing, and analyzing Windows systems.
This is the standalone entry point that uses the modular winflux package.
For development, you can also use: python -m winflux.cli
"""
import click
import logging
import ctypes
from rich.console import Console
from rich.table import Table
# Import from modular package
from winflux.config import setup_logging, load_config, save_config, CONFIG_FILE
from winflux.modules import CleanupModule, AnalyzeModule, OptimizeModule, ReportModule
from winflux.modules.utils import format_bytes
# Initialize console
console = Console()
# Version
__version__ = "1.0.0"
# ASCII Banner
BANNER = """
╦ ╦┬┌┐┌╔═╗┬ ┬ ┬─┐ ┬
║║║││││╠╣ │ │ │┌┴┬┘
╚╩╝┴┘└┘╚ ┴─┘└─┘┴ └─
System Optimizer v{version}
"""
def is_admin():
"""Check if the script is running with admin privileges."""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def show_banner():
"""Display the WinFlux banner."""
config = load_config()
if config.get("show_banner", True):
console.print(BANNER.format(version=__version__), style="bold cyan")
# ============================================================================
# CLI COMMANDS
# ============================================================================
@click.group()
@click.version_option(version=__version__)
@click.pass_context
def cli(ctx):
"""WinFlux - Windows System Optimizer
A powerful CLI tool for cleaning, optimizing, and analyzing your Windows system.
"""
setup_logging()
show_banner()
@cli.command()
@click.option('--dry-run', is_flag=True, help='Preview actions without making changes')
@click.option('--temp', is_flag=True, help='Clean only temporary files')
@click.option('--cache', is_flag=True, help='Clean only browser cache')
@click.option('--all', 'clean_all', is_flag=True, help='Clean everything (default)')
def clean(dry_run, temp, cache, clean_all):
"""Clean temporary files, cache, and junk."""
if dry_run:
console.print("[yellow]🔍 DRY RUN MODE - No changes will be made[/yellow]\n")
config = load_config()
if not dry_run and not config.get('auto_confirm', False):
if not click.confirm('This will delete files. Continue?'):
console.print("[yellow]Operation cancelled.[/yellow]")
return
cleanup = CleanupModule(dry_run=dry_run)
# If no specific option, clean all
if not (temp or cache) or clean_all:
cleanup.clean_temp_files()
cleanup.clean_browser_cache()
cleanup.clean_recycle_bin()
cleanup.clean_junk_files()
else:
if temp:
cleanup.clean_temp_files()
if cache:
cleanup.clean_browser_cache()
console.print(f"\n[bold green]{'Summary (Dry Run)' if dry_run else 'Cleanup Complete!'}[/bold green]")
console.print(f"Total space {'that would be' if dry_run else ''} freed: [bold]{format_bytes(cleanup.freed_space)}[/bold]")
logging.info(f"Cleanup completed. Freed: {format_bytes(cleanup.freed_space)}")
@cli.command()
@click.option('--path', default='C:\\', help='Path to analyze (default: C:\\)')
@click.option('--top', default=10, help='Number of top items to show (default: 10)')
def analyze(path, top):
"""Analyze disk usage and show largest files/folders."""
analyzer = AnalyzeModule()
analyzer.analyze_disk_usage(path=path, top_n=top)
logging.info(f"Disk analysis completed for {path}")
@cli.command()
@click.option('--startup', is_flag=True, help='Show startup programs')
def optimize(startup):
"""Optimize system performance."""
if not is_admin():
console.print("[yellow]⚠️ Some optimizations may require administrator privileges[/yellow]\n")
optimizer = OptimizeModule()
if startup or True: # Default to showing startup
optimizer.list_startup_programs()
logging.info("System optimization completed")
@cli.command()
def report():
"""Generate comprehensive system health report."""
reporter = ReportModule()
reporter.generate_report()
logging.info("System report generated")
@cli.command()
@click.option('--set', 'set_option', help='Set config option (format: key=value)')
@click.option('--show', is_flag=True, help='Show current configuration')
def config(set_option, show):
"""Manage WinFlux configuration."""
current_config = load_config()
if show or (not set_option):
console.print("\n[cyan]Current Configuration:[/cyan]\n")
table = Table(show_header=True)
table.add_column("Option", style="cyan")
table.add_column("Value", style="yellow")
for key, value in current_config.items():
table.add_row(key, str(value))
console.print(table)
console.print(f"\n[dim]Config file: {CONFIG_FILE}[/dim]")
if set_option:
try:
key, value = set_option.split('=')
key = key.strip()
value = value.strip()
# Convert value to appropriate type
if value.lower() == 'true':
value = True
elif value.lower() == 'false':
value = False
current_config[key] = value
save_config(current_config)
console.print(f"[green]✓ Set {key} = {value}[/green]")
except ValueError:
console.print("[red]Invalid format. Use: key=value[/red]")
if __name__ == '__main__':
cli()