Skip to content

Commit

Permalink
feat(win32-api): breaking change genUcsBufferFrom() to ucsBufferFrom()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jul 20, 2022
1 parent a150229 commit 52cc0e5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/win32-api/src/func/user32/index.user32.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
genUcsBufferFrom,
ucsBufferFrom,
ucsBufferToString,
} from '../../index.js'
import { getMod } from '../func.helper.js'
Expand All @@ -21,8 +21,8 @@ export async function user32FindWindowEx(

const mod = getMod<Win32Fns>(dllName)

const lpszClassBuf = genUcsBufferFrom(lpszClass)
const lpszWindowBuf = genUcsBufferFrom(lpszWindow)
const lpszClassBuf = ucsBufferFrom(lpszClass)
const lpszWindowBuf = ucsBufferFrom(lpszWindow)

const hWnd = await mod.FindWindowExW(
hwndParent,
Expand Down
4 changes: 2 additions & 2 deletions packages/win32-api/src/func/winspool/index.winspool.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function winspoolOpenPrinter(printerName: string): Promise<M.HANDLE

assert(printerName)

const nameBuf = genUcsBufferFrom(printerName)
const nameBuf = ucsBufferFrom(printerName)
const ptr = Buffer.alloc(8)
const ret = await mod.OpenPrinterW(nameBuf, ptr, ref.NULL)
if (ret) {
Expand Down
2 changes: 1 addition & 1 deletion packages/win32-api/src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export function retrieveStructFromPtrAddress<R extends StructInstanceBase>(
}


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')
}
Expand Down
6 changes: 3 additions & 3 deletions packages/win32-api/test/70.user32.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
DStruct as DS,
retrieveStructFromPtrAddress,
StructFactory,
genUcsBufferFrom,
ucsBufferFrom,
ucsBufferToString,
} from '../src/index.js'

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions packages/win32-api/test/71.find-calc-async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -69,7 +69,7 @@ async function findNSetWinTitleAsync(): Promise<void> {
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)
Expand All @@ -88,7 +88,7 @@ async function findNSetWinTitleAsyncPartial(): Promise<void> {

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)
Expand Down

0 comments on commit 52cc0e5

Please sign in to comment.