From 52cc0e56e621d802c701e53bf3a852b10c0a32ad Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Wed, 20 Jul 2022 23:15:59 +0800 Subject: [PATCH] feat(win32-api): breaking change genUcsBufferFrom() to ucsBufferFrom() --- packages/win32-api/src/func/user32/index.user32.ts | 6 +++--- packages/win32-api/src/func/winspool/index.winspool.ts | 4 ++-- packages/win32-api/src/lib/helper.ts | 2 +- packages/win32-api/test/70.user32.test.ts | 6 +++--- packages/win32-api/test/71.find-calc-async.test.ts | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/win32-api/src/func/user32/index.user32.ts b/packages/win32-api/src/func/user32/index.user32.ts index 1e8012b7..fda2f606 100644 --- a/packages/win32-api/src/func/user32/index.user32.ts +++ b/packages/win32-api/src/func/user32/index.user32.ts @@ -1,5 +1,5 @@ import { - genUcsBufferFrom, + ucsBufferFrom, ucsBufferToString, } from '../../index.js' import { getMod } from '../func.helper.js' @@ -21,8 +21,8 @@ export async function user32FindWindowEx( const mod = getMod(dllName) - const lpszClassBuf = genUcsBufferFrom(lpszClass) - const lpszWindowBuf = genUcsBufferFrom(lpszWindow) + const lpszClassBuf = ucsBufferFrom(lpszClass) + const lpszWindowBuf = ucsBufferFrom(lpszWindow) const hWnd = await mod.FindWindowExW( hwndParent, diff --git a/packages/win32-api/src/func/winspool/index.winspool.ts b/packages/win32-api/src/func/winspool/index.winspool.ts index f8c8f208..b6be02b6 100644 --- a/packages/win32-api/src/func/winspool/index.winspool.ts +++ b/packages/win32-api/src/func/winspool/index.winspool.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' -import { genUcsBufferFrom, ucsBufferToString } from '../../index.js' +import { ucsBufferFrom, ucsBufferToString } from '../../index.js' import { getMod } from '../func.helper.js' import { Win32Fns, dllName, M, ref } from './helper.js' @@ -46,7 +46,7 @@ export async function winspoolOpenPrinter(printerName: string): Promise( } -export function genUcsBufferFrom(str: string | undefined | null): Buffer { +export function ucsBufferFrom(str: string | undefined | null): Buffer { if (typeof str === 'string' && str.length) { return Buffer.from(str + '\0', 'ucs2') } diff --git a/packages/win32-api/test/70.user32.test.ts b/packages/win32-api/test/70.user32.test.ts index 9bb9ba2a..7a609a87 100644 --- a/packages/win32-api/test/70.user32.test.ts +++ b/packages/win32-api/test/70.user32.test.ts @@ -15,7 +15,7 @@ import { DStruct as DS, retrieveStructFromPtrAddress, StructFactory, - genUcsBufferFrom, + ucsBufferFrom, ucsBufferToString, } from '../src/index.js' @@ -42,7 +42,7 @@ describe(fileShortPath(import.meta.url), () => { assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0, 'found no calc window') // Change title of the Calculator - await user32.SetWindowTextW(hWnd, genUcsBufferFrom(title)) + await user32.SetWindowTextW(hWnd, ucsBufferFrom(title)) const len = title.length assert(len > 0) @@ -85,7 +85,7 @@ describe(fileShortPath(import.meta.url), () => { assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0, 'found no calc window') // Change title of the Calculator - user32Sync.SetWindowTextW(hWnd, genUcsBufferFrom(title)) + user32Sync.SetWindowTextW(hWnd, ucsBufferFrom(title)) const len = title.length + 1 assert(len > 0) diff --git a/packages/win32-api/test/71.find-calc-async.test.ts b/packages/win32-api/test/71.find-calc-async.test.ts index d580deca..ff624e5b 100644 --- a/packages/win32-api/test/71.find-calc-async.test.ts +++ b/packages/win32-api/test/71.find-calc-async.test.ts @@ -4,7 +4,7 @@ import assert from 'node:assert/strict' import { fileShortPath } from '@waiting/shared-core' import { sleep } from 'zx' -import { genUcsBufferFrom, ucsBufferToString } from '../src/index.js' +import { ucsBufferFrom, ucsBufferToString } from '../src/index.js' import * as UP from '../src/index.user32.js' import { calcLpszWindow } from './config.unittest.js' @@ -69,7 +69,7 @@ async function findNSetWinTitleAsync(): Promise { const hWnd = await user32.FindWindowExW(0, 0, null, calcLpszWindow) assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0, 'found no calc window') - const ret = await user32.SetWindowTextW(hWnd, genUcsBufferFrom(title)) + const ret = await user32.SetWindowTextW(hWnd, ucsBufferFrom(title)) assert(ret, 'SetWindowTextW() failed') const buf = Buffer.alloc(len * 2) @@ -88,7 +88,7 @@ async function findNSetWinTitleAsyncPartial(): Promise { assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0, 'found no calc window') // Change title of the Calculator - await u32.SetWindowTextW(hWnd, genUcsBufferFrom(title)) + await u32.SetWindowTextW(hWnd, ucsBufferFrom(title)) const buf = Buffer.alloc(len * 2) await u32.GetWindowTextW(hWnd, buf, len + 1)