this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add fake qrcode

+368 -23
.cache/clangd/index/main.cpp.47C66B394CD74271.idx

This is a binary file and will not be displayed.

.cache/clangd/index/qr.h.B46974D52593BF02.idx

This is a binary file and will not be displayed.

+11 -1
CMakeLists.txt
··· 7 7 # Target Windows XP compatibility 8 8 add_definitions(-DWINVER=0x0501) 9 9 add_definitions(-D_WIN32_WINNT=0x0501) 10 + add_definitions(-D_WIN32_WINNT_WIN2K=0x0500) 11 + add_definitions(-DMINGW_HAS_SECURE_API=1) 12 + 13 + # Disable threading to avoid mcfgthread dependency 14 + add_compile_options(-fno-threadsafe-statics) 15 + add_compile_options(-D_GLIBCXX_HAS_GTHREADS=0) 10 16 11 17 add_executable(HelloWorldApp WIN32 main.cpp) 12 18 target_link_libraries(HelloWorldApp user32 gdi32) 13 19 14 - # Minimal static linking 20 + # Include current directory for headers 21 + target_include_directories(HelloWorldApp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 22 + 23 + # Minimal static linking and avoid threading dependencies 15 24 target_link_options(HelloWorldApp PRIVATE 16 25 -static-libgcc 17 26 -static-libstdc++ 27 + -static 18 28 -Wl,--subsystem,windows:5.01 19 29 ) 20 30
+82 -12
flake.nix
··· 36 36 ''; 37 37 38 38 buildPhase = '' 39 + export LDFLAGS="-static -static-libgcc -static-libstdc++" 39 40 cmake -DCMAKE_BUILD_TYPE=Release \ 40 41 -DCMAKE_SYSTEM_NAME=Windows \ 41 42 -DCMAKE_C_COMPILER=$CC \ 42 - -DCMAKE_CXX_COMPILER=$CXX . 43 + -DCMAKE_CXX_COMPILER=$CXX \ 44 + -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" . 43 45 make VERBOSE=1 44 46 ''; 45 47 ··· 52 54 deploy-to-xp = pkgs.writeShellScriptBin "deploy-to-xp" '' 53 55 XP_DIR="$HOME/Documents/xp-drive" 54 56 mkdir -p "$XP_DIR" 55 - cp ${self'.packages.hello-world-app}/bin/HelloWorld.exe "$XP_DIR/" 56 - echo "Deployed HelloWorld.exe to $XP_DIR" 57 + 58 + # Handle Windows file locking by using a temporary name first 59 + TEMP_NAME="HelloWorld_new.exe" 60 + OLD_NAME="HelloWorld_old.exe" 61 + FINAL_NAME="HelloWorld.exe" 62 + 63 + echo "Deploying to $XP_DIR..." 64 + 65 + # Copy to temporary name first 66 + if cp ${self'.packages.hello-world-app}/bin/HelloWorld.exe "$XP_DIR/$TEMP_NAME"; then 67 + echo "✓ Copied new version as $TEMP_NAME" 68 + 69 + # If the original exists, try to rename it 70 + if [ -f "$XP_DIR/$FINAL_NAME" ]; then 71 + if mv "$XP_DIR/$FINAL_NAME" "$XP_DIR/$OLD_NAME" 2>/dev/null; then 72 + echo "✓ Backed up old version as $OLD_NAME" 73 + else 74 + echo "⚠ Warning: Could not backup old version (file may be in use)" 75 + echo " Close the application on XP and try again, or manually rename files" 76 + echo " New version is available as: $TEMP_NAME" 77 + exit 1 78 + fi 79 + fi 80 + 81 + # Move temp to final name 82 + if mv "$XP_DIR/$TEMP_NAME" "$XP_DIR/$FINAL_NAME"; then 83 + echo "✓ Deployed HelloWorld.exe successfully" 84 + 85 + # Clean up old backup if it exists 86 + if [ -f "$XP_DIR/$OLD_NAME" ]; then 87 + rm -f "$XP_DIR/$OLD_NAME" 2>/dev/null || echo " (Old backup file remains)" 88 + fi 89 + else 90 + echo "✗ Failed to finalize deployment" 91 + exit 1 92 + fi 93 + else 94 + echo "✗ Failed to copy new version" 95 + exit 1 96 + fi 97 + 98 + echo "" 99 + echo "Deployment complete! 🎉" 100 + echo "You can now run the updated application on XP" 57 101 ''; 58 102 59 103 setup-dev = pkgs.writeShellScriptBin "setup-dev" '' 60 104 echo "Setting up development environment for Zed..." 61 105 62 106 # Get the proper MinGW headers - use the known path from our build 107 + GCC_BASE="/nix/store/l2gk3vvpdf33jf3gnfljyyx3dgwks8zp-i686-w64-mingw32-stage-final-gcc-debug-10.3.0/i686-w64-mingw32" 108 + SYS_INCLUDE="$GCC_BASE/sys-include" 63 109 MINGW_MAIN_INCLUDE="/nix/store/hhbkp872dkayzd2qxfhkdc4rgn393g52-mingw-w64-i686-w64-mingw32-9.0.0-dev/include" 110 + MCFGTHREAD_INCLUDE="/nix/store/21c6w351iwpblnfz2m9v3ssvxcmqsz7h-mcfgthreads-i686-w64-mingw32-git-dev/include" 111 + CPP_INCLUDE="$GCC_BASE/include/c++/10.3.0" 112 + CPP_TARGET_INCLUDE="$CPP_INCLUDE/i686-w64-mingw32" 64 113 65 - # Verify it exists, if not try to find it dynamically 114 + # Verify paths exist 115 + if [ ! -f "$SYS_INCLUDE/stdlib.h" ]; then 116 + echo "Error: Could not find C standard library at $SYS_INCLUDE" 117 + exit 1 118 + fi 119 + 66 120 if [ ! -f "$MINGW_MAIN_INCLUDE/windows.h" ]; then 67 - echo "Static path not found, searching dynamically..." 68 - MINGW_MAIN_INCLUDE=$(i686-w64-mingw32-gcc -v -E - < /dev/null 2>&1 | sed -n '/mingw-w64.*-dev\/include/p' | head -1 | awk '{print $2}') 69 - 70 - if [ -z "$MINGW_MAIN_INCLUDE" ] || [ ! -f "$MINGW_MAIN_INCLUDE/windows.h" ]; then 71 - echo "Error: Could not find proper MinGW headers with windows.h" 72 - exit 1 73 - fi 121 + echo "Error: Could not find MinGW headers at $MINGW_MAIN_INCLUDE" 122 + exit 1 123 + fi 124 + 125 + if [ ! -f "$CPP_INCLUDE/vector" ]; then 126 + echo "Error: Could not find C++ standard library at $CPP_INCLUDE" 127 + exit 1 128 + fi 129 + 130 + if [ ! -f "$MCFGTHREAD_INCLUDE/mcfgthread/gthread.h" ]; then 131 + echo "Error: Could not find mcfgthread headers at $MCFGTHREAD_INCLUDE" 132 + exit 1 74 133 fi 75 134 76 135 # Create simplified .clangd config to avoid intrinsics issues ··· 87 146 - -std=c++17 88 147 - -fno-builtin 89 148 - -D__NO_INLINE__ 149 + - -isystem 150 + - $SYS_INCLUDE 90 151 - -isystem 91 152 - $MINGW_MAIN_INCLUDE 153 + - -isystem 154 + - $MCFGTHREAD_INCLUDE 155 + - -isystem 156 + - $CPP_INCLUDE 157 + - -isystem 158 + - $CPP_TARGET_INCLUDE 92 159 Remove: 93 160 - -I*/gcc/*/include 94 161 EOF ··· 105 172 EOF 106 173 107 174 echo "Generated simplified .clangd config and compile_commands.json" 175 + echo "Using C standard library: $SYS_INCLUDE" 108 176 echo "Using MinGW headers: $MINGW_MAIN_INCLUDE" 177 + echo "Using mcfgthread headers: $MCFGTHREAD_INCLUDE" 178 + echo "Using C++ headers: $CPP_INCLUDE" 109 179 echo "" 110 - echo "This avoids GCC intrinsics that cause clang issues" 180 + echo "This includes complete C/C++ standard libraries and Win32 APIs" 111 181 echo "Restart Zed for the changes to take effect" 112 182 ''; 113 183
+99 -10
main.cpp
··· 1 1 #include <windows.h> 2 + #include "qr.h" 2 3 3 4 #define ID_ABOUT 1001 4 5 #define ID_EXIT 1002 6 + #define ID_GENERATE_QR 1003 5 7 6 8 LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 9 + 10 + // Global QR code instance - static allocation, no new/delete 11 + QRCode g_qrCode; 12 + BOOL g_hasQrCode = FALSE; 13 + char g_qrText[256] = "Hello World!"; 7 14 8 15 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { 9 16 const char* CLASS_NAME = "HelloWorldWindow"; ··· 34 41 35 42 // Create menu 36 43 HMENU hMenu = CreateMenu(); 37 - HMENU hSubMenu = CreatePopupMenu(); 38 44 39 - AppendMenu(hSubMenu, MF_STRING, ID_ABOUT, "&About"); 40 - AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); 41 - AppendMenu(hSubMenu, MF_STRING, ID_EXIT, "E&xit"); 42 - AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "&Help"); 45 + // Tools menu 46 + HMENU hToolsMenu = CreatePopupMenu(); 47 + AppendMenu(hToolsMenu, MF_STRING, ID_GENERATE_QR, "&Generate QR Pattern"); 48 + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hToolsMenu, "&Tools"); 49 + 50 + // Help menu 51 + HMENU hHelpMenu = CreatePopupMenu(); 52 + AppendMenu(hHelpMenu, MF_STRING, ID_ABOUT, "&About"); 53 + AppendMenu(hHelpMenu, MF_SEPARATOR, 0, NULL); 54 + AppendMenu(hHelpMenu, MF_STRING, ID_EXIT, "E&xit"); 55 + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hHelpMenu, "&Help"); 43 56 44 57 SetMenu(hwnd, hMenu); 45 58 ··· 57 70 58 71 LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 59 72 switch (uMsg) { 73 + case WM_SIZE: 74 + // Trigger repaint when window is resized 75 + InvalidateRect(hwnd, NULL, TRUE); 76 + return 0; 77 + 60 78 case WM_DESTROY: 79 + // No cleanup needed for static allocation 61 80 PostQuitMessage(0); 62 81 return 0; 63 82 ··· 68 87 RECT rect; 69 88 GetClientRect(hwnd, &rect); 70 89 71 - // Center the text 72 - SetTextAlign(hdc, TA_CENTER); 73 - SetBkMode(hdc, TRANSPARENT); 74 - TextOut(hdc, rect.right / 2, rect.bottom / 2 - 10, "Hello World!", 12); 90 + if (g_hasQrCode) { 91 + // Draw QR code - calculate size based on window 92 + int qrSize = QRCode_GetSize(); 93 + int moduleSize = 8; 94 + int qrPixelSize = qrSize * moduleSize; 95 + 96 + // Center horizontally and vertically with some padding 97 + int startX = (rect.right - qrPixelSize) / 2; 98 + int startY = (rect.bottom - qrPixelSize - 80) / 2; // Leave space for text 99 + 100 + QRCode_DrawToHDC(&g_qrCode, hdc, startX, startY, moduleSize); 101 + 102 + // Draw text below QR code 103 + SetTextAlign(hdc, TA_CENTER); 104 + SetBkMode(hdc, TRANSPARENT); 105 + int textLen = 0; 106 + while (g_qrText[textLen]) textLen++; // Calculate length 107 + TextOut(hdc, rect.right / 2, startY + qrPixelSize + 20, 108 + g_qrText, textLen); 109 + 110 + // Add disclaimer 111 + const char* disclaimer = "(Visual demo - not scannable)"; 112 + int disclaimerLen = 0; 113 + while (disclaimer[disclaimerLen]) disclaimerLen++; 114 + TextOut(hdc, rect.right / 2, startY + qrPixelSize + 40, 115 + disclaimer, disclaimerLen); 116 + } else { 117 + // Default view - center in current window size 118 + SetTextAlign(hdc, TA_CENTER); 119 + SetBkMode(hdc, TRANSPARENT); 120 + int centerY = rect.bottom / 2; 121 + TextOut(hdc, rect.right / 2, centerY - 10, "Hello World!", 12); 122 + TextOut(hdc, rect.right / 2, centerY + 10, 123 + "Use Tools > Generate QR Pattern", 32); 124 + } 75 125 76 126 EndPaint(hwnd, &ps); 77 127 return 0; ··· 84 134 "Version: 1.0.0\n" 85 135 "Built by: Kieran Klukas\n\n" 86 136 "A simple Win32 application\n" 87 - "compatible with Windows XP"; 137 + "compatible with Windows XP\n\n" 138 + "Features:\n" 139 + "- QR Pattern Generation (visual demo)\n" 140 + "- XP Compatible Design\n" 141 + "- Pure Win32 API"; 88 142 MessageBox(hwnd, aboutText, "About Hello World App", 89 143 MB_OK | MB_ICONINFORMATION); 144 + break; 145 + } 146 + case ID_GENERATE_QR: { 147 + // Simple input dialog using InputBox simulation 148 + if (MessageBox(hwnd, "Generate QR code pattern for current text?\n\n(Note: This creates a visual QR-like pattern for demo purposes,\nnot a scannable QR code)\n\nClick OK to use default text,\nor Cancel to cycle through presets.", 149 + "Generate QR Pattern", MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL) { 150 + 151 + // For now, use a simple preset - in a real app you'd want a proper input dialog 152 + const char* presets[] = { 153 + "Hello World!", 154 + "https://github.com/taciturnaxolotl/shortwave", 155 + "Made with love by Kieran Klukas", 156 + "Windows XP Forever!", 157 + "QR codes are cool!" 158 + }; 159 + 160 + static int presetIndex = 0; 161 + const char* selectedText = presets[presetIndex % 5]; 162 + presetIndex++; 163 + 164 + // Copy selected text to global buffer 165 + int i = 0; 166 + while (selectedText[i] && i < 255) { 167 + g_qrText[i] = selectedText[i]; 168 + i++; 169 + } 170 + g_qrText[i] = '\0'; 171 + } 172 + 173 + // Generate new QR code - no new/delete, just reinitialize 174 + QRCode_Init(&g_qrCode, g_qrText); 175 + g_hasQrCode = TRUE; 176 + 177 + // Refresh the window 178 + InvalidateRect(hwnd, NULL, TRUE); 90 179 break; 91 180 } 92 181 case ID_EXIT:
+176
qr.h
··· 1 + #pragma once 2 + #include <windows.h> 3 + 4 + #define QR_SIZE 21 5 + #define MAX_TEXT_LEN 256 6 + 7 + // Pure C struct for QR code - no C++ classes 8 + typedef struct { 9 + BOOL modules[QR_SIZE][QR_SIZE]; 10 + char text[MAX_TEXT_LEN]; 11 + } QRCode; 12 + 13 + // Function prototypes 14 + void QRCode_Init(QRCode* qr, const char* inputText); 15 + void QRCode_GeneratePattern(QRCode* qr); 16 + void QRCode_AddFinderPattern(QRCode* qr, int x, int y); 17 + BOOL QRCode_IsReserved(int x, int y); 18 + void QRCode_DrawToHDC(QRCode* qr, HDC hdc, int startX, int startY, int moduleSize); 19 + int QRCode_GetSize(void); 20 + const char* QRCode_GetText(QRCode* qr); 21 + 22 + // Implementation 23 + void QRCode_Init(QRCode* qr, const char* inputText) { 24 + int x, y, i; 25 + 26 + // Initialize modules array 27 + for (y = 0; y < QR_SIZE; y++) { 28 + for (x = 0; x < QR_SIZE; x++) { 29 + qr->modules[y][x] = FALSE; 30 + } 31 + } 32 + 33 + // Copy text (safe copy) 34 + i = 0; 35 + while (inputText[i] && i < MAX_TEXT_LEN - 1) { 36 + qr->text[i] = inputText[i]; 37 + i++; 38 + } 39 + qr->text[i] = '\0'; 40 + 41 + // Generate pattern 42 + QRCode_GeneratePattern(qr); 43 + } 44 + 45 + void QRCode_GeneratePattern(QRCode* qr) { 46 + int i, x, y; 47 + unsigned int hash = 0; 48 + unsigned char textBytes[MAX_TEXT_LEN]; 49 + int textLen = 0; 50 + 51 + // Add finder patterns (corners) 52 + QRCode_AddFinderPattern(qr, 0, 0); 53 + QRCode_AddFinderPattern(qr, QR_SIZE - 7, 0); 54 + QRCode_AddFinderPattern(qr, 0, QR_SIZE - 7); 55 + 56 + // Add timing patterns 57 + for (i = 8; i < QR_SIZE - 8; i++) { 58 + qr->modules[6][i] = (i % 2 == 0) ? TRUE : FALSE; 59 + qr->modules[i][6] = (i % 2 == 0) ? TRUE : FALSE; 60 + } 61 + 62 + // Convert text to bytes and calculate length 63 + while (qr->text[textLen] && textLen < MAX_TEXT_LEN - 1) { 64 + textBytes[textLen] = (unsigned char)qr->text[textLen]; 65 + textLen++; 66 + } 67 + 68 + // Add format information (fake but realistic looking) 69 + // These would normally encode error correction level and mask pattern 70 + qr->modules[8][0] = TRUE; 71 + qr->modules[8][1] = FALSE; 72 + qr->modules[8][2] = TRUE; 73 + qr->modules[8][3] = TRUE; 74 + qr->modules[8][4] = FALSE; 75 + qr->modules[8][5] = TRUE; 76 + 77 + // Add data in a more realistic zigzag pattern 78 + int bitIndex = 0; 79 + BOOL upward = TRUE; 80 + 81 + for (x = QR_SIZE - 1; x > 0; x -= 2) { 82 + if (x == 6) x--; // Skip timing column 83 + 84 + for (i = 0; i < QR_SIZE; i++) { 85 + y = upward ? (QR_SIZE - 1 - i) : i; 86 + 87 + // Fill two columns (right to left) 88 + for (int col = 0; col < 2; col++) { 89 + int currentX = x - col; 90 + if (currentX >= 0 && !QRCode_IsReserved(currentX, y)) { 91 + // Use text data in a more structured way 92 + BOOL bit = FALSE; 93 + if (bitIndex < textLen * 8) { 94 + int byteIndex = bitIndex / 8; 95 + int bitPos = 7 - (bitIndex % 8); 96 + bit = (textBytes[byteIndex] >> bitPos) & 1; 97 + bitIndex++; 98 + } else { 99 + // Padding pattern 100 + bit = ((currentX + y) % 3 == 0) ? TRUE : FALSE; 101 + } 102 + qr->modules[y][currentX] = bit; 103 + } 104 + } 105 + } 106 + upward = !upward; 107 + } 108 + } 109 + 110 + void QRCode_AddFinderPattern(QRCode* qr, int x, int y) { 111 + int dx, dy; 112 + BOOL dark; 113 + 114 + for (dy = 0; dy < 7; dy++) { 115 + for (dx = 0; dx < 7; dx++) { 116 + if (x + dx < QR_SIZE && y + dy < QR_SIZE) { 117 + dark = (dx == 0 || dx == 6 || dy == 0 || dy == 6 || 118 + (dx >= 2 && dx <= 4 && dy >= 2 && dy <= 4)) ? TRUE : FALSE; 119 + qr->modules[y + dy][x + dx] = dark; 120 + } 121 + } 122 + } 123 + } 124 + 125 + BOOL QRCode_IsReserved(int x, int y) { 126 + // Check if position is part of finder patterns 127 + if ((x < 9 && y < 9) || 128 + (x >= QR_SIZE - 8 && y < 9) || 129 + (x < 9 && y >= QR_SIZE - 8)) { 130 + return TRUE; 131 + } 132 + 133 + // Check timing patterns 134 + if (x == 6 || y == 6) { 135 + return TRUE; 136 + } 137 + 138 + // Check format information areas 139 + if ((x < 9 && y == 8) || (x == 8 && y < 9)) { 140 + return TRUE; 141 + } 142 + if ((x >= QR_SIZE - 8 && y == 8) || (x == 8 && y >= QR_SIZE - 7)) { 143 + return TRUE; 144 + } 145 + 146 + return FALSE; 147 + } 148 + 149 + void QRCode_DrawToHDC(QRCode* qr, HDC hdc, int startX, int startY, int moduleSize) { 150 + HBRUSH blackBrush = CreateSolidBrush(RGB(0, 0, 0)); 151 + HBRUSH whiteBrush = CreateSolidBrush(RGB(255, 255, 255)); 152 + int x, y; 153 + RECT rect; 154 + 155 + for (y = 0; y < QR_SIZE; y++) { 156 + for (x = 0; x < QR_SIZE; x++) { 157 + rect.left = startX + x * moduleSize; 158 + rect.top = startY + y * moduleSize; 159 + rect.right = startX + (x + 1) * moduleSize; 160 + rect.bottom = startY + (y + 1) * moduleSize; 161 + 162 + FillRect(hdc, &rect, qr->modules[y][x] ? blackBrush : whiteBrush); 163 + } 164 + } 165 + 166 + DeleteObject(blackBrush); 167 + DeleteObject(whiteBrush); 168 + } 169 + 170 + int QRCode_GetSize(void) { 171 + return QR_SIZE; 172 + } 173 + 174 + const char* QRCode_GetText(QRCode* qr) { 175 + return qr->text; 176 + }