The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Studio: preserve Unicode paths in Windows file dialogs (#49)
Abram Freemanb92c29240b7f
diff --git a/.changeset/windows-picker-utf8.md b/.changeset/windows-picker-utf8.mdnew file mode 100644index 0000000..1c2901c--- /dev/null+++ b/.changeset/windows-picker-utf8.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Preserve Unicode file and folder paths in Windows Studio dialogs so importing media from paths containing non-ASCII characters works correctly.diff --git a/packages/openfilm/studio/server/folder-picker.mjs b/packages/openfilm/studio/server/folder-picker.mjsindex 4113bd9..3b0796e 100644--- a/packages/openfilm/studio/server/folder-picker.mjs+++ b/packages/openfilm/studio/server/folder-picker.mjs@@ -69,6 +69,8 @@ export function folderPickerCommand(platform, { title, at }, has = () => true) {}if (platform === 'win32') {const script = [+ // Match execFile's UTF-8 decoding, including paths outside the Windows console code page.+ '[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding','Add-Type -AssemblyName System.Windows.Forms','$d = New-Object System.Windows.Forms.FolderBrowserDialog','$d.Description = $env:OPENFILM_PICK_TITLE',@@ -112,6 +114,8 @@ export function filePickerCommand(platform, { title, at }, has = () => true) {}if (platform === 'win32') {const script = [+ // Match execFile's UTF-8 decoding, including paths outside the Windows console code page.+ '[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding','Add-Type -AssemblyName System.Windows.Forms','$d = New-Object System.Windows.Forms.OpenFileDialog','$d.Title = $env:OPENFILM_PICK_TITLE',@@ -165,7 +169,7 @@ export function pickFolder(ask) {const command = folderPickerCommand(process.platform, { ...ask, at: startFolder(ask.at) }, onPath);if (!command) return Promise.reject(new Error('no folder dialog on this system'));return new Promise((resolve, reject) => {- execFile(command.cmd, command.args, { env: { ...process.env, ...command.env }, windowsHide: false, timeout: 15 * 60_000 }, (error, stdout) => {+ execFile(command.cmd, command.args, { env: { ...process.env, ...command.env }, encoding: 'utf8', windowsHide: false, timeout: 15 * 60_000 }, (error, stdout) => {const path = String(stdout).trim().replace(/[\\/]+$/, '') || (String(stdout).trim() === '/' ? '/' : '');if (path) { resolve(path); return; }if (cancelled(command.cmd, error)) { resolve(null); return; }@@ -184,7 +188,7 @@ export function pickFiles(ask) {const command = filePickerCommand(process.platform, { ...ask, at: startFolder(ask.at) }, onPath);if (!command) return Promise.reject(new Error('no file dialog on this system'));return new Promise((resolve, reject) => {- execFile(command.cmd, command.args, { env: { ...process.env, ...command.env }, windowsHide: false, timeout: 15 * 60_000 }, (error, stdout) => {+ execFile(command.cmd, command.args, { env: { ...process.env, ...command.env }, encoding: 'utf8', windowsHide: false, timeout: 15 * 60_000 }, (error, stdout) => {const paths = String(stdout).split(/\r?\n/).map((line) => line.trim()).filter((line) => line && isAbsolute(line));if (paths.length) { resolve(paths); return; }if (cancelled(command.cmd, error)) { resolve([]); return; }diff --git a/packages/openfilm/studio/server/folder-picker.test.mjs b/packages/openfilm/studio/server/folder-picker.test.mjsindex f3fa388..f46f8bd 100644--- a/packages/openfilm/studio/server/folder-picker.test.mjs+++ b/packages/openfilm/studio/server/folder-picker.test.mjs@@ -1,4 +1,5 @@import { test } from 'node:test';+import { execFileSync } from 'node:child_process';import assert from 'node:assert/strict';import { cancelled, filePickerCommand, folderPickerCommand, startFolder } from './folder-picker.mjs';@@ -70,3 +71,18 @@ test('macOS: the starting folder is made before Finder is asked, and one that isassert.ok(lines.indexOf('set startAt to (POSIX file (item 2 of argv)) as alias') < lines.indexOf('tell application "Finder"'));assert.ok(!lines.some((l) => l.includes('default location (POSIX file')), 'Finder never makes a path a folder itself');});++for (const [kind, picker] of [['folder', folderPickerCommand], ['files', filePickerCommand]]) {+ test(`Windows: ${kind} paths survive PowerShell output as UTF-8`, { skip: process.platform !== 'win32', timeout: 15_000 }, () => {+ const paths = ['D:\\音频素材\\承诺 🎵.mp3', 'Z:\\日本語\\música.wav'];+ const expected = kind === 'folder' ? paths[0] : paths.join('\n');+ const command = picker('win32', { title: 'Choose' });+ // Run the command's output setup without opening an interactive dialog. The chosen paths come from the environment.+ const script = command.args.at(-1).replace(/Add-Type[\s\S]*$/, '[Console]::Out.Write($env:OPENFILM_PICK_TEST_PATHS)');+ const stdout = execFileSync(command.cmd, [...command.args.slice(0, -1), script], {+ env: { ...process.env, ...command.env, OPENFILM_PICK_TEST_PATHS: expected },+ encoding: 'utf8', windowsHide: true, timeout: 10_000,+ });+ assert.equal(stdout, expected);+ });+}