Compare commits

...
Author SHA1 Message Date
agrynco 8ef13ca9bd Record the package manifest for KSwitcher v0.6.108 2026-11-17 10:56:21 +02:00
agrynco c0eca89738 Release KSwitcher v0.6.108 with Wake-on-LAN in Files 2026-11-17 10:55:01 +02:00
agrynco 0b6709495b Release KSwitcher v0.6.107 (#52)
Files command suggestions, contextual Windows help, and the FAR-style icon.
2026-11-16 23:12:42 +02:00
15 changed files with 496 additions and 96 deletions

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.24)
project(KSwitcher VERSION 0.6.107 LANGUAGES CXX RC)
project(KSwitcher VERSION 0.6.108 LANGUAGES CXX RC)
if(NOT WIN32)
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
endif()
+9
View File
@@ -102,6 +102,15 @@ Warning і початковий фокус на No.
**Options → Command line → Command history → Allow paired PCs to hibernate this PC**.
Дозвіл за замовчуванням вимкнений і діє лише для спарених ПК. Для цієї дії
потрібні оновлення на обох ПК і ввімкнена гібернація Windows.
- У **Change drive** (Alt+F1 або Alt+F2) підкреслена дія **Wake** є праворуч
від стану офлайн-ПК. Клік по слову або Enter з фокусом на дії надсилає пакет.
Статус відображається на тлі списку. Для текстових дій усередині рядків
використовуй спільний компонент `InlineListAction` для малювання, фокуса
й обробки кліків. KSwitcher
має зберегти MAC-адресу мережевого адаптера. Оновіть KSwitcher та дайте
обом ПК побачити один одного в локальній мережі. На цільовому ПК потрібна
підтримка Wake-on-LAN у прошивці та налаштуваннях адаптера. Рядок стану
повідомляє про надсилання пакета або відсутність збереженої MAC-адреси.
- **F9 → Commands → Update remote KSwitcher** запускає штатне оновлення для
ПК активної LAN-панелі. Підтвердження з іменем ПК показується у Files
відправника. На цільовому ПК потрібен дозвіл **Options → Command line →
+12
View File
@@ -1,5 +1,17 @@
# Latest Windows release
## v0.6.108 — 2026-11-17
KSwitcher Files adds **Wake** beside the offline status of a paired PC in **Change drive** (Alt+F1 or Alt+F2). Click **Wake** or focus it with the arrow keys and press **Enter**. The status bar reports whether KSwitcher sent the Wake-on-LAN packet.
Update both PCs and let them discover each other once while the target is online so KSwitcher can save its network adapter’s MAC address. Enable Wake-on-LAN on the target. Ethernet is the most reliable option. Wi-Fi requires compatible Wake on Wireless LAN hardware and drivers.
**Українською.**
У KSwitcher Files біля статусу спареного офлайн-ПК у меню **Change drive** (Alt+F1 або Alt+F2) є дія **Wake**. Клацніть **Wake** або виберіть її стрілками й натисніть **Enter**. Рядок стану повідомить, чи вдалося надіслати пакет Wake-on-LAN.
Оновіть обидва ПК і дайте їм один раз побачити один одного, поки цільовий ПК увімкнено, щоб KSwitcher зберіг MAC-адресу його мережевого адаптера. Увімкніть Wake-on-LAN на цільовому ПК. Найнадійніше підключення через Ethernet. Для Wi-Fi потрібна підтримка Wake on Wireless LAN з боку обладнання й драйвера.
## v0.6.107 — 2026-11-16
KSwitcher Files suggests recent commands, PowerShell commands and parameters, and paths as you type. The list works with the panes visible or hidden. Use **Up** or **Down** to select, **Tab** or **Enter** on a selected suggestion to insert it, and **Escape** to close the list. Press **F1** in the command line to open the Microsoft Learn article for a documented Windows command or subcommand.
+1 -1
View File
@@ -1 +1 @@
1f817ebc455d579b42e2e6f822107b7c2341c9cd5dcbb60b023fb41b0ebd6266 KSwitcher-win-x64.zip
57cb29bf72f335c7b3dff5c40a1b992b46c770f3106b6033f7b02819c665a139 KSwitcher-win-x64.zip
+39 -39
View File
@@ -1,166 +1,166 @@
{
"files": [
{
"size": 2479104,
"path": "KSwitcher.exe",
"size": 2369536,
"sha256": "b23677961181dc430c3e22b44acd3aa4abc07c4876b8d2e7e50e47b93eb732a4"
"sha256": "eb8c6aacf2fb626b135d89b4b416dbed4e12519f9d5cca4fa3fe27bfdac524f5"
},
{
"size": 2457600,
"path": "KSwitcher.Config.exe",
"size": 2366464,
"sha256": "475c12d6ed8a74ae09f6ca6b974ee98767a900e4c0023a86c87eccb2bb63b091"
"sha256": "542c14cc509bf5e6f9e85e4c53d7b7624289a7f53015d5d7b2213b551e987575"
},
{
"size": 3060224,
"path": "KSwitcher.Screenshot.exe",
"size": 3346432,
"sha256": "3b3752d56c70267a1da5ba5c5665d24248254b98ec68188f39abbfc713f2d6b1"
"sha256": "077a3a83da0fd0055f55b7df49b6c7fdf9e9ceb6eaaf7c3b20a98fb81b9a3a43"
},
{
"size": 4208128,
"path": "KSwitcher.Files.exe",
"size": 4022784,
"sha256": "fc741a294166ca1b27efeb393d4d236ac043320186fdcbd3ce558f0ab48de80a"
"sha256": "41a77a9b94005373ee02ed83143d7f4927926fa6a57a379988d482de39825519"
},
{
"path": "WebView2Loader.dll",
"size": 194912,
"path": "WebView2Loader.dll",
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6"
},
{
"path": "terminal/addon-fit-LICENSE.txt",
"size": 1103,
"path": "terminal/addon-fit-LICENSE.txt",
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f"
},
{
"path": "terminal/addon-fit.js",
"size": 1521,
"path": "terminal/addon-fit.js",
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527"
},
{
"path": "terminal/index.html",
"size": 527,
"path": "terminal/index.html",
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef"
},
{
"path": "terminal/markdown-it-LICENSE.txt",
"size": 1073,
"path": "terminal/markdown-it-LICENSE.txt",
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473"
},
{
"path": "terminal/markdown-it.js",
"size": 100786,
"path": "terminal/markdown-it.js",
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e"
},
{
"path": "terminal/markdown.html",
"size": 3530,
"path": "terminal/markdown.html",
"sha256": "e5381c35fb254b558c8b869746e2e575c8ed53600611ac90597ed2dd80fa321c"
},
{
"path": "terminal/markdown.js",
"size": 14987,
"path": "terminal/markdown.js",
"sha256": "5d1e824df1c3570877e985de0cfaae3f2984ceef7fe23bf4c5ade3c890a93223"
},
{
"path": "terminal/mermaid-LICENSE.txt",
"size": 1089,
"path": "terminal/mermaid-LICENSE.txt",
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80"
},
{
"path": "terminal/mermaid.js",
"size": 5537838,
"path": "terminal/mermaid.js",
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3"
},
{
"path": "terminal/terminal.js",
"size": 5033,
"path": "terminal/terminal.js",
"sha256": "0557d251962301940785690a3fc49475dd166bb7d0bd0417dc3279d1f1b3a98a"
},
{
"path": "terminal/xterm-LICENSE.txt",
"size": 1261,
"path": "terminal/xterm-LICENSE.txt",
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd"
},
{
"path": "terminal/xterm.css",
"size": 7112,
"path": "terminal/xterm.css",
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6"
},
{
"path": "terminal/xterm.js",
"size": 488663,
"path": "terminal/xterm.js",
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972"
},
{
"path": "LICENSE",
"size": 4401,
"path": "LICENSE",
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c"
},
{
"path": "json-LICENSE.txt",
"size": 1096,
"path": "json-LICENSE.txt",
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831"
},
{
"path": "files-text-license.txt",
"size": 883,
"path": "files-text-license.txt",
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625"
},
{
"path": "README.md",
"size": 94908,
"path": "README.md",
"sha256": "12d8b55a2d2f26060b2a614bd52e6e0ffe4a8f140e62cc454a47fc8f246cb81f"
},
{
"path": "LAN-PREVIEW.md",
"size": 11577,
"path": "LAN-PREVIEW.md",
"sha256": "1233d6a0ed76564dd034f178a9f65db076244a819137f74dc9f2c27df9d3c930"
},
{
"path": "dictionaries/en.txt",
"size": 732485,
"path": "dictionaries/en.txt",
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9"
},
{
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
"size": 20566,
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5"
},
{
"path": "dictionaries/README.md",
"size": 2265,
"path": "dictionaries/README.md",
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311"
},
{
"path": "dictionaries/ru.txt",
"size": 1109134,
"path": "dictionaries/ru.txt",
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849"
},
{
"path": "dictionaries/sources.json",
"size": 1280,
"path": "dictionaries/sources.json",
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408"
},
{
"path": "dictionaries/uk.txt",
"size": 940799,
"path": "dictionaries/uk.txt",
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf"
},
{
"path": "tools/README.txt",
"size": 993,
"path": "tools/README.txt",
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a"
},
{
"size": 133120,
"path": "tools/StayHere.exe",
"size": 134656,
"sha256": "6ef5cf64708d62b7fc63c3c793cc99188a513433ff4774cae01dc014f6664376"
"sha256": "6945ac336307301285ade8d98939e3bb974d1e20b3414101a8e1e50ce31ababb"
},
{
"path": "tools/StayHere-README.md",
"size": 2796,
"path": "tools/StayHere-README.md",
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413"
}
],
"version": "0.6.107",
"schema": 1
"schema": 1,
"version": "0.6.108"
}
+3 -3
View File
@@ -9,8 +9,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
1 RT_MANIFEST "app.manifest"
201 RCDATA "update.ps1"
1 VERSIONINFO
FILEVERSION 0,6,107,0
PRODUCTVERSION 0,6,107,0
FILEVERSION 0,6,108,0
PRODUCTVERSION 0,6,108,0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
BEGIN
@@ -20,7 +20,7 @@ BEGIN
BEGIN
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
VALUE "ProductName", "KSwitcher"
VALUE "FileVersion", "0.6.107"
VALUE "FileVersion", "0.6.108"
END
END
BLOCK "VarFileInfo"
+69
View File
@@ -0,0 +1,69 @@
#pragma once
#include <windows.h>
#include <algorithm>
#include <string_view>
#include <windowsx.h>
namespace ks::files
{
inline COLORREF hoverSurface(COLORREF surface)
{
return RGB(3*GetRValue(surface)/4,3*GetGValue(surface)/4,3*GetBValue(surface)/4);
}
class InlineListAction
{
std::wstring_view label;
LRESULT pressedRow=LB_ERR;
public:
explicit InlineListAction(std::wstring_view text):label(text){}
RECT bounds(RECT row,int cellWidth) const
{
row.right-=2*cellWidth;
row.left=std::max(row.left,row.right-static_cast<LONG>(label.size()*cellWidth));
return row;
}
bool hit(HWND list,LRESULT row,LPARAM point,int cellWidth) const
{
RECT item{};
if(SendMessageW(list,LB_GETITEMRECT,row,reinterpret_cast<LPARAM>(&item))==LB_ERR) return false;
const auto action=bounds(item,cellWidth);
return PtInRect(&action,{GET_X_LPARAM(point),GET_Y_LPARAM(point)});
}
void press(HWND list,LRESULT row)
{
pressedRow=row;
SetCapture(list);
}
bool pressed() const { return pressedRow!=LB_ERR; }
void cancel() { pressedRow=LB_ERR; }
bool release(HWND list,LRESULT row,bool overAction)
{
const bool activate=pressedRow==row && overAction;
cancel();
if(GetCapture()==list) ReleaseCapture();
return activate;
}
void paint(HDC dc,const RECT &action,int textInset,COLORREF ink,COLORREF surface,bool highlighted) const
{
SetTextColor(dc,ink);
SetBkColor(dc,highlighted?hoverSurface(surface):surface);
ExtTextOutW(dc,action.left,action.top+textInset,ETO_OPAQUE|ETO_CLIPPED,&action,
label.data(),static_cast<UINT>(label.size()),nullptr);
TEXTMETRICW metrics{};
GetTextMetricsW(dc,&metrics);
const LONG underline=std::min(action.bottom-1,action.top+textInset+metrics.tmAscent+1);
const RECT line{action.left,underline,action.right,underline+1};
SetDCBrushColor(dc,ink);
FillRect(dc,&line,static_cast<HBRUSH>(GetStockObject(DC_BRUSH)));
}
};
}
+117 -24
View File
@@ -27,10 +27,12 @@
#include "files_text_preferences.h"
#include "files_menu_paint.h"
#include "files_dropdown_paint.h"
#include "files_inline_action.h"
#include "files_history_date.h"
#include "files_terminal_view.h"
#include "files_lan_ipc.h"
#include "lan_files.h"
#include "lan_wake.h"
#include "platform.h"
namespace
@@ -429,7 +431,9 @@ struct DriveQuery
Json drives=Json::array();
std::wstring error;
};
struct DriveChoice { FilesPeer peer; fs::path path; };
struct DriveChoice { FilesPeer peer; std::optional<fs::path> path; };
constexpr wchar_t driveWakeLabel[]=L"Wake";
ks::files::InlineListAction driveWakeAction(driveWakeLabel);
std::vector<DriveQuery> driveQueries;
std::map<LRESULT,DriveChoice> remoteDriveRows;
constexpr UINT_PTR driveQueryTimer=3;
@@ -2042,6 +2046,45 @@ void prepareTextDialog(HWND dialog);
void showTextMessage(HWND owner,const wchar_t *text);
void editTextOptions(HWND owner,bool edit);
void startPeerAction(std::packaged_task<std::wstring()> task,const std::wstring &status)
{
pendingPeerAction=task.get_future();
try {std::thread(std::move(task)).detach();}
catch(const std::system_error &error)
{
pendingPeerAction={};
setStatus(fileError(error));
return;
}
setStatus(status);
}
void wakeRemotePeer(const FilesPeer &peer)
{
if(pendingPeerAction.valid())
{
setStatus(L"A remote PC request is already in progress.");
return;
}
std::packaged_task<std::wstring()> task([peer]
{
try
{
ks::lan::wakeFilesPeer(peer.id);
return peer.name+L": Wake-on-LAN packet sent.";
}
catch(const std::system_error &error)
{
return peer.name+L": Could not send Wake-on-LAN packet. "+fileError(error);
}
catch(const std::exception &error)
{
return peer.name+L": "+ks::wide(error.what());
}
});
startPeerAction(std::move(task),L"Sending Wake-on-LAN packet to "+peer.name+L"...");
}
void runActivePeerAction(HWND owner,bool update)
{
if(!panels[active].peer) return;
@@ -2091,15 +2134,8 @@ void runActivePeerAction(HWND owner,bool update)
return unconfirmed;
}
});
pendingPeerAction=task.get_future();
try {std::thread(std::move(task)).detach();}
catch(const std::system_error &error)
{
pendingPeerAction={};
setStatus(fileError(error));
return;
}
setStatus((update?L"Requesting a KSwitcher update on ":L"Requesting hibernation for ")+peer.name+L"...");
startPeerAction(std::move(task),
(update?L"Requesting a KSwitcher update on ":L"Requesting hibernation for ")+peer.name+L"...");
}
void selectDrive()
@@ -2140,7 +2176,11 @@ void selectDrive()
if(row>=0 && static_cast<size_t>(row)<drivePaths.size())
openOn(panels[pickerPanel],drivePaths[row],false,{});
else if(remote!=remoteDriveRows.end())
openOn(panels[pickerPanel],remote->second.path,false,remote->second.peer);
{
const auto &choice=remote->second;
if(choice.path) openOn(panels[pickerPanel],*choice.path,false,choice.peer);
else wakeRemotePeer(choice.peer);
}
}
LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
@@ -2173,6 +2213,29 @@ LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PT
if(!HIWORD(hit) && separator(LOWORD(hit))) return 0;
}
}
if(msg==WM_CAPTURECHANGED) driveWakeAction.cancel();
if(!commandPicker && (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP || msg==WM_LBUTTONDBLCLK))
{
const auto hit=SendMessageW(window,LB_ITEMFROMPOINT,0,lp);
const int row=HIWORD(hit)?-1:LOWORD(hit);
const auto choice=remoteDriveRows.find(row);
const bool wake=choice!=remoteDriveRows.end() && !choice->second.path;
if(msg==WM_LBUTTONUP && driveWakeAction.pressed())
{
if(driveWakeAction.release(window,row,wake && driveWakeAction.hit(window,row,lp,cellWidth)))
{
SendMessageW(window,LB_SETCURSEL,row,0);
selectDrive();
}
return 0;
}
if(wake && msg!=WM_LBUTTONUP)
{
if(msg==WM_LBUTTONDOWN && driveWakeAction.hit(window,row,lp,cellWidth))
driveWakeAction.press(window,row);
return 0;
}
}
if(!commandPicker && msg==WM_CHAR)
{
const auto key=towupper(static_cast<wchar_t>(wp));
@@ -2198,7 +2261,14 @@ LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PT
TRACKMOUSEEVENT tracking{sizeof(tracking),TME_LEAVE,window,0};
TrackMouseEvent(&tracking);
const auto hit=SendMessageW(window,LB_ITEMFROMPOINT,0,lp);
if(!HIWORD(hit) && LOWORD(hit)<drivePaths.size()) row=LOWORD(hit);
if(!HIWORD(hit))
{
const auto choice=remoteDriveRows.find(LOWORD(hit));
if(LOWORD(hit)<drivePaths.size() ||
(choice!=remoteDriveRows.end() && !choice->second.path &&
driveWakeAction.hit(window,LOWORD(hit),lp,cellWidth)))
row=LOWORD(hit);
}
}
if(driveHover!=row)
{
@@ -2334,19 +2404,27 @@ void showRemoteDrives(bool focus=false,int initialRow=0)
for(const auto &query:driveQueries)
{
add(query.peer.name);
if(query.pending.valid()) add(L" Loading drives...");
const auto addChoice=[&](const std::wstring &label,std::optional<fs::path> path)
{
const auto row=add(label);
if(row<0) return;
if(previous && previous->peer.id==query.peer.id && previous->path==path) selection=row;
remoteDriveRows.emplace(row,DriveChoice{query.peer,std::move(path)});
};
if(query.peer.address.empty())
{
const std::wstring status=nextDriveRefresh?L" Looking for PC...":L" Offline";
addChoice(status+L" \t"+driveWakeLabel,std::nullopt);
}
else if(query.pending.valid()) add(L" Loading drives...");
else if(!query.error.empty()) add(L" "+query.error);
else if(query.peer.address.empty()) add(nextDriveRefresh?L" Looking for PC...":L" Offline");
else if(query.drives.empty()) add(L" No drives");
for(const auto &entry:query.drives)
{
const auto root=filePath(entry.at("path"));
if(root.native().size()!=3 || root.native().front()<L'A' || root.native().front()>L'Z') continue;
const auto labels=driveLabels(root.native().front(),entry.at("type"),entry.at("total"),entry.at("free"));
const auto row=add(L" "+labels[0]+L" "+labels[1]+L" "+labels[2]);
if(row<0) continue;
remoteDriveRows.emplace(row,DriveChoice{query.peer,root});
if(previous && previous->peer.id==query.peer.id && previous->path==root) selection=row;
addChoice(L" "+labels[0]+L" "+labels[1]+L" "+labels[2],root);
}
}
layoutDrivePicker(static_cast<int>(selection),focus);
@@ -5433,7 +5511,8 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
const auto rows=Json::parse(begin,begin+reply->cbData);
if(!rows.is_array()) return FALSE;
for(const auto &row:rows)
drivePeers.push_back({row.at("id"),row.at("address"),ks::wide(row.at("name")),ks::lan::FilesPort,row.value("filesBrowse",false)});
drivePeers.push_back({row.at("id"),row.at("address"),ks::wide(row.at("name")),ks::lan::FilesPort,
row.value("filesBrowse",false)});
}
catch(const std::exception &){drivePeers.clear();return FALSE;}
drivePeerReplyReceived=true;
@@ -5876,8 +5955,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
SelectObject(item.hDC,mono);
SetTextColor(item.hDC,foreground);
const auto normal=colors[Dialog];
const auto hover=RGB(3*GetRValue(normal)/4,3*GetGValue(normal)/4,
3*GetBValue(normal)/4);
const auto hover=ks::files::hoverSurface(normal);
SetBkColor(item.hDC,background==Dialog && static_cast<int>(item.itemID)==driveHover?
hover:colors[background]);
ExtTextOutW(item.hDC,0,0,ETO_OPAQUE,&item.rcItem,L"",0,nullptr);
@@ -5915,12 +5993,27 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
else if(item.hwndItem==picker && !commandPicker && item.itemID>drivePaths.size())
{
auto bounds=item.rcItem;
RECT button{};
const auto choice=remoteDriveRows.find(item.itemID);
const bool wake=choice!=remoteDriveRows.end() && !choice->second.path;
SelectObject(item.hDC,mono);
SetTextColor(item.hDC,foreground);
SetBkColor(item.hDC,colors[background]);
SetBkColor(item.hDC,colors[wake?Dialog:background]);
if(wake)
{
button=driveWakeAction.bounds(bounds,cellWidth);
if(shortcut!=std::wstring::npos) text.resize(shortcut);
ExtTextOutW(item.hDC,0,0,ETO_OPAQUE,&bounds,L"",0,nullptr);
bounds.right=button.left;
}
ExtTextOutW(item.hDC,bounds.left+driveColumnStarts[0],bounds.top+3,
ETO_OPAQUE|ETO_CLIPPED,&bounds,text.c_str(),lstrlenW(text.c_str()),nullptr);
ETO_OPAQUE|ETO_CLIPPED,&bounds,text.c_str(),static_cast<UINT>(text.size()),nullptr);
if(wake)
{
const bool focused=(item.itemState&ODS_SELECTED) && GetFocus()==picker;
driveWakeAction.paint(item.hDC,button,3,foreground,colors[Dialog],
focused || static_cast<int>(item.itemID)==driveHover);
}
}
else if(item.CtlID>=130 && item.CtlID<=134)
paintMenuLabel(item.hDC,item.rcItem,text,0,foreground,colors[background]);
+87 -4
View File
@@ -7,6 +7,8 @@
#include "lan_mesh.h"
#include "lan_clipboard.h"
#include "lan_layout.h"
#include "lan_network.h"
#include "lan_wake.h"
#include <atomic>
#include <mutex>
#include <thread>
@@ -28,14 +30,41 @@ std::string hostName()
wchar_t name[256]{}; DWORD size=256;
return GetComputerNameW(name,&size) ? utf8(std::wstring(name,size)) : "KSwitcher";
}
std::vector<ULONG> broadcasts()
Bytes ipv4Adapters()
{
ULONG size=16384; Bytes data(size);
auto flags=GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST|GAA_FLAG_SKIP_DNS_SERVER;
auto result=GetAdaptersAddresses(AF_INET,flags,nullptr,(IP_ADAPTER_ADDRESSES*)data.data(),&size);
if(result==ERROR_BUFFER_OVERFLOW) { data.resize(size); result=GetAdaptersAddresses(AF_INET,flags,nullptr,(IP_ADAPTER_ADDRESSES*)data.data(),&size); }
if(result!=NO_ERROR) return {};
return data;
}
std::string wakeMacFor(ULONG remote)
{
DWORD interfaceIndex{};
if(GetBestInterface(remote,&interfaceIndex)!=NO_ERROR) return {};
auto data=ipv4Adapters();
if(data.empty()) return {};
for(auto a=reinterpret_cast<const IP_ADAPTER_ADDRESSES*>(data.data());a;a=a->Next)
{
if(a->IfIndex!=interfaceIndex || a->OperStatus!=IfOperStatusUp || a->PhysicalAddressLength!=6 ||
(a->IfType!=IF_TYPE_ETHERNET_CSMACD && a->IfType!=IF_TYPE_IEEE80211)) continue;
std::string result;
for(size_t i=0;i<a->PhysicalAddressLength;++i)
{
const auto byte=a->PhysicalAddress[i];
result+="0123456789abcdef"[byte>>4];
result+="0123456789abcdef"[byte&15];
}
return lan::wakePacket(result)?result:std::string{};
}
return {};
}
std::vector<ULONG> broadcasts()
{
auto data=ipv4Adapters();
std::vector<ULONG> out;
if(result!=NO_ERROR) return out;
if(data.empty()) return out;
for(auto a=(IP_ADAPTER_ADDRESSES*)data.data();a;a=a->Next)
if(a->OperStatus==IfOperStatusUp)
for(auto u=a->FirstUnicastAddress;u;u=u->Next)
@@ -47,6 +76,38 @@ std::vector<ULONG> broadcasts()
return out;
}
}
void lan::wakeFilesPeer(const std::string &id)
{
const auto settings=Json::parse(unprotect(readFile(dataDirectory()/L"lan-pairing.bin",256*1024)));
const auto &trusted=settings.at("trusted");
if(!settings.value("enabled",false) || !trusted.contains(id))
throw std::runtime_error("Enable KSwitcher LAN and select a paired PC.");
const auto packet=wakePacket(trusted.at(id).value("wakeMac",""));
if(!packet) throw std::runtime_error("No saved MAC address. Run updated KSwitcher on this PC while it is online once.");
const auto destinations=broadcasts();
if(destinations.empty()) throw std::runtime_error("No local IPv4 network is available.");
Network network;
WinSocket socket{::socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)};
if(socket.value==INVALID_SOCKET) socketError();
const BOOL broadcast=TRUE;
if(setsockopt(socket.value,SOL_SOCKET,SO_BROADCAST,reinterpret_cast<const char*>(&broadcast),sizeof(broadcast)))
socketError();
bool sent=false;
int error=WSAEHOSTUNREACH;
for(const auto ip:destinations)
{
sockaddr_in destination{};
destination.sin_family=AF_INET;
destination.sin_port=htons(9);
destination.sin_addr.s_addr=ip;
if(sendto(socket.value,reinterpret_cast<const char*>(packet->data()),static_cast<int>(packet->size()),0,
reinterpret_cast<const sockaddr*>(&destination),sizeof(destination))==SOCKET_ERROR)
error=WSAGetLastError();
else sent=true;
}
if(!sent) throw std::system_error(error,std::system_category());
}
struct LanService::Impl
{
struct Peer { std::string name,epoch; sockaddr_in address{}; uint64_t seen{},verified{}; bool files{}; };
@@ -231,7 +292,15 @@ struct LanService::Impl
if(trusted.contains(other))
{
auto response=lan::envelope("presence",id); response["to"]=other; response["epoch"]=epoch;
response["proof"]=lan::mac(trusted[other].at("key"),heartbeat(id,other,epoch,session));
const auto &key=trusted[other].at("key");
const auto challenge=heartbeat(id,other,epoch,session);
response["proof"]=lan::mac(key,challenge);
const auto wakeMac=wakeMacFor(address.sin_addr.s_addr);
if(!wakeMac.empty())
{
response["wakeMac"]=wakeMac;
response["wakeProof"]=lan::mac(key,challenge+"|wake|"+wakeMac);
}
send(socket,address,response);
}
return;
@@ -260,7 +329,21 @@ struct LanService::Impl
}
if(type=="presence" && trusted.contains(other) && j.value("epoch","")==peer.epoch &&
lan::equal(j.value("proof",""),lan::mac(trusted[other].at("key"),heartbeat(other,id,peer.epoch,epoch))))
{ peer.verified=now; return; }
{
peer.verified=now;
auto &entry=trusted.at(other);
const auto wakeMac=j.value("wakeMac","");
if(lan::wakePacket(wakeMac) && wakeMac!=entry.value("wakeMac","") &&
lan::equal(j.value("wakeProof",""),
lan::mac(entry.at("key"),heartbeat(other,id,peer.epoch,epoch)+"|wake|"+wakeMac)))
{
auto previous=entry;
entry["wakeMac"]=wakeMac;
try {save();}
catch(const std::exception &){entry=std::move(previous);}
}
return;
}
if(pending && pending->peer==other)
{
for(const auto &response:pending->receive(j,now)) send(socket,address,response);
+1 -22
View File
@@ -14,6 +14,7 @@
#include <thread>
#include "lan_files.h"
#include "lan_channel.h"
#include "lan_network.h"
namespace ks::lan
{
@@ -111,28 +112,6 @@ DWORD createJunction(const fs::path &name,const fs::path &target)
constexpr size_t FrameLimit=256*1024;
constexpr DWORD SocketTimeout=5000;
struct WinSocket
{
SOCKET value=INVALID_SOCKET;
~WinSocket(){if(value!=INVALID_SOCKET) closesocket(value);}
};
void socketError()
{
throw std::system_error(WSAGetLastError(),std::system_category());
}
struct Network
{
Network()
{
WSADATA data{};
if(const auto error=WSAStartup(MAKEWORD(2,2),&data))
throw std::system_error(error,std::system_category());
}
~Network(){WSACleanup();}
};
class Wire
{
SOCKET socket;
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <winsock2.h>
#include <system_error>
namespace ks::lan
{
inline void socketError()
{
throw std::system_error(WSAGetLastError(),std::system_category());
}
struct WinSocket
{
SOCKET value=INVALID_SOCKET;
~WinSocket(){if(value!=INVALID_SOCKET) closesocket(value);}
};
struct Network
{
Network()
{
WSADATA data{};
if(const auto error=WSAStartup(MAKEWORD(2,2),&data))
throw std::system_error(error,std::system_category());
}
~Network(){WSACleanup();}
};
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <algorithm>
#include <array>
#include <optional>
#include <string>
#include <string_view>
namespace ks::lan
{
inline std::optional<std::array<unsigned char,102>> wakePacket(std::string_view mac)
{
constexpr std::string_view digits="0123456789abcdef";
std::array<unsigned char,6> address{};
if(mac.size()!=2*address.size()) return {};
for(size_t i=0;i<address.size();++i)
{
const auto high=digits.find(mac[2*i]),low=digits.find(mac[2*i+1]);
if(high==digits.npos || low==digits.npos) return {};
address[i]=static_cast<unsigned char>(16*high+low);
}
if((address.front()&1) || std::all_of(address.begin(),address.end(),[](auto byte){return byte==0;}))
return {};
std::array<unsigned char,102> packet{};
std::fill_n(packet.begin(),6,0xff);
for(auto next=packet.begin()+6;next!=packet.end();next+=address.size())
std::copy(address.begin(),address.end(),next);
return packet;
}
void wakeFilesPeer(const std::string &id);
}
+1 -1
View File
@@ -2,7 +2,7 @@
#include "platform.h"
namespace ks
{
inline constexpr wchar_t AppVersion[] = L"0.6.107";
inline constexpr wchar_t AppVersion[] = L"0.6.108";
inline constexpr UINT UpdateMessage = WM_APP + 7;
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
+74 -1
View File
@@ -1,15 +1,26 @@
param([string]$Executable = "$PSScriptRoot/../build/files-dev/KSwitcher.Files.exe")
param(
[string]$Executable = "$PSScriptRoot/../build/files-dev/KSwitcher.Files.exe",
[switch]$OfflineWake,
[string]$Screenshot
)
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName System.Drawing
Add-Type @'
using System;
using System.Text;
using System.Runtime.InteropServices;
public static class FilesDriveShortcutTest {
[StructLayout(LayoutKind.Sequential)]
public struct Rect { public int Left, Top, Right, Bottom; }
[DllImport("user32.dll")] public static extern IntPtr GetDlgItem(IntPtr window, int id);
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr window);
[DllImport("user32.dll")] public static extern bool PostMessage(IntPtr window, uint msg, IntPtr w, IntPtr l);
[DllImport("user32.dll", CharSet=CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr window, uint msg, IntPtr w, StringBuilder text);
[DllImport("user32.dll", EntryPoint="SendMessageW")]
public static extern IntPtr SendRect(IntPtr window, uint msg, IntPtr w, out Rect rect);
[DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr window, out Rect rect);
[DllImport("user32.dll")] public static extern bool PrintWindow(IntPtr window, IntPtr dc, uint flags);
}
'@
function Wait-Until([scriptblock]$Condition) {
@@ -38,6 +49,68 @@ try {
[void][FilesDriveShortcutTest]::PostMessage($picker, 258, [IntPtr][int]$Key, [IntPtr]::Zero)
Wait-Until { ![FilesDriveShortcutTest]::IsWindowVisible($picker) }
}
if ($OfflineWake) {
function Read-Picker {
$count = [FilesDriveShortcutTest]::SendMessage($picker, 395, [IntPtr]::Zero, $null).ToInt32()
for ($i = 0; $i -lt $count; $i++) { Read-Text $picker 393 $i }
}
function Render-Picker {
$client = [FilesDriveShortcutTest+Rect]::new()
[void][FilesDriveShortcutTest]::GetClientRect($picker, [ref]$client)
$bitmap = [Drawing.Bitmap]::new($client.Right, $client.Bottom)
$graphics = [Drawing.Graphics]::FromImage($bitmap)
try {
$dc = $graphics.GetHdc()
try {
if (![FilesDriveShortcutTest]::PrintWindow($picker, $dc, 2)) { throw 'Could not render drive picker.' }
} finally { $graphics.ReleaseHdc($dc) }
return $bitmap
} finally { $graphics.Dispose() }
}
function Click-Picker([int]$X, [int]$Y) {
$point = [IntPtr](($Y -shl 16) -bor $X)
[void][FilesDriveShortcutTest]::PostMessage($picker, 513, [IntPtr]1, $point)
[void][FilesDriveShortcutTest]::PostMessage($picker, 514, [IntPtr]::Zero, $point)
}
Open-Picker
$rows = @(Read-Picker)
$wake = -1
for ($i = 0; $i -lt $rows.Count; $i++) {
if ($rows[$i] -match '^ (Offline|Looking for PC\.\.\.) \tWake$') { $wake = $i; break }
}
if ($wake -lt 0) { throw 'This check requires an offline paired PC with a Wake action.' }
$rect = [FilesDriveShortcutTest+Rect]::new()
[void][FilesDriveShortcutTest]::SendRect($picker, 408, [IntPtr]$wake, [ref]$rect)
$original = [FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null)
Click-Picker ($rect.Left + 16) ([int](($rect.Top + $rect.Bottom) / 2))
Start-Sleep -Milliseconds 100
if (![FilesDriveShortcutTest]::IsWindowVisible($picker) -or
[FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null) -ne $original) {
throw 'Clicking outside the Wake label selected or activated the status row.'
}
[void][FilesDriveShortcutTest]::PostMessage($picker, 675, [IntPtr]::Zero, [IntPtr]::Zero)
$normal = Render-Picker
[void][FilesDriveShortcutTest]::SendMessage($picker, 390, [IntPtr]$wake, $null)
$focused = Render-Picker
try {
$changed = @(for ($x = $rect.Left; $x -lt [Math]::Min($rect.Right, $normal.Width); $x++) {
if ($normal.GetPixel($x,$rect.Top) -ne $focused.GetPixel($x,$rect.Top)) { $x }
})
$width = $rect.Right - $rect.Left
if (!$changed.Count -or $changed[0] -lt ($rect.Left + $width / 2) -or $changed[-1] -ge $rect.Right - 2) {
throw 'Wake focus must highlight only the inline action and leave the status and trailing space unchanged.'
}
if ($Screenshot) { $focused.Save($Screenshot, [Drawing.Imaging.ImageFormat]::Png) }
Click-Picker ([int](($changed[0]+$changed[-1])/2)) ([int](($rect.Top+$rect.Bottom)/2))
Wait-Until { ![FilesDriveShortcutTest]::IsWindowVisible($picker) }
} finally { $normal.Dispose(); $focused.Dispose() }
Open-Picker
[void][FilesDriveShortcutTest]::SendMessage($picker, 390, [IntPtr]$wake, $null)
[void][FilesDriveShortcutTest]::PostMessage($picker, 256, [IntPtr]13, [IntPtr]::Zero)
Wait-Until { ![FilesDriveShortcutTest]::IsWindowVisible($picker) }
Write-Output 'Wake focus and mouse activation are limited to the inline action. Enter activates the focused action.'
return
}
Open-Picker
$count = [FilesDriveShortcutTest]::SendMessage($picker, 395, [IntPtr]::Zero, $null).ToInt32()
$rows = @(for ($i = 0; $i -lt $count; $i++) { Read-Text $picker 393 $i })
+23
View File
@@ -1,5 +1,6 @@
#include "lan.h"
#include "lan_pairing.h"
#include "lan_wake.h"
#include <iostream>
#include <tlhelp32.h>
@@ -29,6 +30,15 @@ int main(int argc,char **argv)
check(identifier(randomHex(16)),"cryptographic instance ID");
check(mac("key","The quick brown fox jumps over the lazy dog")=="f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", "HMAC SHA256 known vector");
check(equal("abc","abc")&&!equal("abc","abd")&&!equal("abc","ab"),"proof comparison");
const auto magic=wakePacket("02468ace1357");
const std::array<unsigned char,6> hardwareAddress{0x02,0x46,0x8a,0xce,0x13,0x57};
check(magic && std::all_of(magic->begin(),magic->begin()+6,[](auto byte){return byte==0xff;}),
"Wake-on-LAN synchronization bytes");
for(size_t repeat=0;repeat<16;++repeat)
check(std::equal(hardwareAddress.begin(),hardwareAddress.end(),magic->begin()+6*(repeat+1)),
"Wake-on-LAN repeats the target MAC address");
check(!wakePacket("ffffffffffff") && !wakePacket("000000000000") &&
!wakePacket("023456789abx") && !wakePacket("023456789ab"),"invalid Wake-on-LAN addresses rejected");
Pairing left(a,b,code,100),right(b,a,code,100),wrong(b,a,std::string(32,'f'),100);
check(wrong.receive(left.offer(),101).empty(),"different code cannot acknowledge");
auto forged=left.offer();forged["id"]=c;
@@ -118,6 +128,19 @@ int main(int argc,char **argv)
check(request(restored,{{"action","status"}})["peers"].empty(),"forget removes offline pair");
check(!request(restored,{{"action","status"}}).at("shareInput").get<bool>(),"forgetting the input peer revokes persisted input permission");
}
{
const auto folder=root/L"wake";
std::filesystem::create_directory(folder);
const auto saved=Json{{"version",1},{"id",a},{"enabled",true},{"trusted",{
{b,{{"name","Wake peer"},{"key",left.derived},{"wakeMac","02468ace1357"}}},
{c,{{"name","Legacy peer"},{"key",left.derived}}}}}}.dump();
atomicWrite(folder/L"lan-pairing.bin",protect(Bytes(saved.begin(),saved.end())));
LanService restored(folder);
const auto peers=request(restored,{{"action","filesPeers"}}).at("peers");
check(peers.size()==2 && peers[0].at("id")==b && peers[0].at("address")=="" &&
peers[1].at("id")==c,"offline PCs remain selectable in Files with or without a saved MAC address");
check(peers.dump().find("02468ace1357")==std::string::npos,"Files snapshot omits the stored MAC address");
}
if(argc>1&&std::string(argv[1])=="--network")
{
auto saved=Json::parse(unprotect(readFile(root/L"lan-pairing.bin",256*1024)));