Skip to content

Commit 54e7ea7

Browse files
initial commit.
0 parents  commit 54e7ea7

File tree

7 files changed

+860
-0
lines changed

7 files changed

+860
-0
lines changed

.github/workflows/cpp-check.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: C/C++ CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build-windows:
11+
runs-on: windows-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup MSVC
17+
uses: ilammy/msvc-dev-cmd@v1
18+
19+
- name: Build
20+
run: cl /EHsc main.cpp

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# output
2+
winoptimizer.exe
3+
4+
# temp files of ide's
5+
.vscode
6+
.nvim
7+
.idea

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
TARGET = winoptimizer.exe
2+
SRC_DIR = src
3+
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
4+
5+
CXXFLAGS = -O2 -std=c++20 -Iinclude
6+
7+
ifeq ($(OS),Windows_NT)
8+
CXX = g++
9+
EXE =
10+
SYSTEMCXXFLAGS = -static
11+
else
12+
CXX = x86_64-w64-mingw32-g++
13+
EXE = .exe
14+
SYSTEMCXXFLAGS = -static -static-libgcc -static-libstdc++
15+
endif
16+
17+
all: $(TARGET)
18+
19+
$(TARGET): $(SRCS)
20+
$(CXX) $(CXXFLAGS) $(SYSTEMCXXFLAGS) $(SRCS) -o $(TARGET)
21+
22+
clean:
23+
rm -f $(TARGET)

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div align="center">
2+
3+
# WindowsOptimizer
4+
5+
A free and open-source Windows optimalization software.
6+
7+
</div>
8+
9+
There are a lot of free Windows optimalization scams out there and we want to provide a software that does the same for you, but for free. WindowsOptimizer does just that, while being fully open source, so if you don't trust us, you can check the code yourself and compile it on your machine.
10+
11+
## Building
12+
13+
Use GNU Make to compile the project. The Makefile can build .exe from Linux, as long as `x86_64-w64-mingw32-g++` and `x86_64-w64-mingw32-binutils` are installed.
14+
15+
On Windows you can download `make` from [this website](https://gnuwin32.sourceforge.net/packages/make.htm).
16+
17+
> [!TIP]
18+
> While the binary does compile on Linux, it is recommended to use normal Windows machine for testing, because Wine does not emulate all required stuff.
19+

include/ids.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define GENERATE_ID(unique) unique + 100
2+
3+
#define ID_CHECK_UPDATE GENERATE_ID(1)
4+
#define ID_CHECK_TEMP GENERATE_ID(2)
5+
#define ID_CHECK_SYSTEM GENERATE_ID(3)
6+
#define ID_OPTIMIZE GENERATE_ID(4)

src/main.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include <filesystem>
2+
#include <ids.hpp>
3+
#include <windows.h>
4+
5+
HWND hCheckUpdate;
6+
HWND hCheckTemp;
7+
HWND hCheckSystem;
8+
9+
void clear_directory(const std::filesystem::path& path) {
10+
if (!std::filesystem::exists(path)) return;
11+
for (auto& entry : std::filesystem::directory_iterator(path)) {
12+
std::error_code ec;
13+
std::filesystem::remove_all(entry.path(), ec);
14+
}
15+
}
16+
17+
void optimize() {
18+
if (SendMessageA(hCheckUpdate, BM_GETCHECK, 0, 0) == BST_CHECKED) {
19+
clear_directory("C:\\Windows\\SoftwareDistribution\\Download");
20+
}
21+
22+
if (SendMessageA(hCheckTemp, BM_GETCHECK, 0, 0) == BST_CHECKED) {
23+
char tempPath[MAX_PATH];
24+
GetTempPathA(MAX_PATH, tempPath);
25+
clear_directory(tempPath);
26+
}
27+
28+
if (SendMessageA(hCheckSystem, BM_GETCHECK, 0, 0) == BST_CHECKED) {
29+
clear_directory("C:\\Windows\\Temp");
30+
}
31+
32+
MessageBoxA(NULL, "Optimization complete", "Done", MB_OK | MB_ICONINFORMATION);
33+
}
34+
35+
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
36+
switch (msg) {
37+
case WM_COMMAND:
38+
if (LOWORD(wParam) == ID_OPTIMIZE) {
39+
optimize();
40+
}
41+
break;
42+
43+
case WM_DESTROY:
44+
PostQuitMessage(0);
45+
break;
46+
47+
default:
48+
return DefWindowProcA(hwnd, msg, wParam, lParam);
49+
}
50+
return 0;
51+
}
52+
53+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nShowCmd) {
54+
WNDCLASSA wc{};
55+
wc.lpfnWndProc = WndProc;
56+
wc.hInstance = hInstance;
57+
wc.lpszClassName = "OptimizerApp";
58+
59+
RegisterClassA(&wc);
60+
61+
HWND hwnd = CreateWindowExA(
62+
0,
63+
"OptimizerApp",
64+
"Windows Optimizer",
65+
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
66+
CW_USEDEFAULT, CW_USEDEFAULT, 360, 240,
67+
NULL, NULL, hInstance, NULL
68+
);
69+
70+
hCheckUpdate = CreateWindowA(
71+
"BUTTON",
72+
"Clear Windows Update cache",
73+
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
74+
20, 20, 300, 25,
75+
hwnd, (HMENU)ID_CHECK_UPDATE, hInstance, NULL
76+
);
77+
78+
hCheckTemp = CreateWindowA(
79+
"BUTTON",
80+
"Clear user TEMP",
81+
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
82+
20, 50, 300, 25,
83+
hwnd, (HMENU)ID_CHECK_TEMP, hInstance, NULL
84+
);
85+
86+
hCheckSystem = CreateWindowA(
87+
"BUTTON",
88+
"Clear system TEMP",
89+
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
90+
20, 80, 300, 25,
91+
hwnd, (HMENU)ID_CHECK_SYSTEM, hInstance, NULL
92+
);
93+
94+
CreateWindowA(
95+
"BUTTON",
96+
"OPTIMIZE",
97+
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
98+
20, 130, 300, 40,
99+
hwnd, (HMENU)ID_OPTIMIZE, hInstance, NULL
100+
);
101+
102+
ShowWindow(hwnd, nShowCmd);
103+
104+
MSG msg;
105+
while (GetMessageA(&msg, NULL, 0, 0)) {
106+
TranslateMessage(&msg);
107+
DispatchMessageA(&msg);
108+
}
109+
110+
return 0;
111+
}

0 commit comments

Comments
 (0)