From ab5454815701e90c15383ccfde16ecec71d3955f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 23:25:24 +0000 Subject: [PATCH 1/2] Profiles and the watched folder keep their "keep the source" tick Loading a profile on the Convert page filled BOTH pages from the file again. The watched folder lost its own options that way: a "keep the source" ticked there went out, and the next find was moved away. The controls a profile has just set are now written into the file instead, and the watched folder is left alone. "Shut down when finished" no longer comes back from a profile's copy of the file either. A profile's copy of the file is brought into line with the controls it is saved from, and the list of settings is read fresh before saving. A copy that was older than the boxes could contradict the profile's own tick. The watched folder recognises results in the "output" subfolder. With originals kept, every restart of the window handed the whole stock to the converter again. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01GvUq7F6HRPWfTUBjDkD1bR --- frontend/check_harness.js | 3 +- frontend/dist/index.html | 63 ++++++++++++++++++++++++++++++++++++--- frontend/mirror_check.js | 49 +++++++++++++++++++++++++++++- watchfolder.go | 32 ++++++++++++++++++++ watchfolder_test.go | 43 ++++++++++++++++++++++++++ 5 files changed, 184 insertions(+), 6 deletions(-) diff --git a/frontend/check_harness.js b/frontend/check_harness.js index 5d72fde..920e65c 100644 --- a/frontend/check_harness.js +++ b/frontend/check_harness.js @@ -331,7 +331,8 @@ function loadGui() { " checkUpdate, installUpdate, download," + " INI_MIRROR, seedOptionsFromConfig, rememberOption, rememberCQ, saveOneSetting," + " noteCodecReach, afterOptionsChanged," + - " settingsSnapshot, ensureSettingsFile, applyProfileSettings, noteShutdownFromConfig, refreshConfig };" + " settingsSnapshot, ensureSettingsFile, applyProfileSettings, noteShutdownFromConfig, refreshConfig," + + " loadSettings, mirroredValues, profileSettings };" )(windowStub, documentStub); return { diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 56437f2..ec655ad 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -3614,6 +3614,25 @@

The PC is shutting down

saveOneSetting(entry.key, entry.toIni(el)); } +// mirroredValues reads the Convert page's mirrored controls as lines for the +// INI: key and value, for every key the file really has. +// +// Two places need the whole set at once rather than one control at a time — +// saving a profile and loading one. Both are about the same promise: what the +// boxes show and what the file says must never drift apart. +function mirroredValues() { + const out = {}; + const config = state.config; + if (!config || !config.found) return out; + INI_MIRROR.forEach((entry) => { + if (entry.fromConfig(config) === null) return; + const el = $("opt-" + entry.id); + if (!el) return; + out[entry.key] = entry.toIni(el); + }); + return out; +} + // The CQ box needs its own handler: which key it belongs to depends on the // codec. function rememberCQ() { @@ -4519,11 +4538,30 @@

The PC is shutting down

fixedCQ: parseInt($("opt-cq").value, 10) || 0, keepSource: $("opt-keep").checked, crop: $("opt-crop").checked, - settings: settingsSnapshot(), + settings: profileSettings(), parallel: parallelSetting() }; } +// profileSettings is the INI copy a profile takes along, brought into line +// with the controls it is saved from. +// +// The copy comes from the settings list as it was last read, and that can be +// older than the boxes: with unsaved edits on the settings page the list is +// not read again (refreshConfig). A profile saved in that moment said "keep +// the source" in its tick and keepSource=false in its copy of the file — and +// on loading, the file's word came out on top. Where the two overlap, the +// controls on show are what was saved. +function profileSettings() { + const snapshot = settingsSnapshot(); + if (!snapshot) return null; + const shown = mirroredValues(); + Object.keys(shown).forEach((key) => { + if (key in snapshot) snapshot[key] = shown[key]; + }); + return snapshot; +} + // applyProfile writes a saved set into the controls of one page. The prefix // says which page: "opt" is Convert, "wopt" the watched folder. Both name // their fields the same way, which is what lets one profile serve both. @@ -4639,14 +4677,28 @@

The PC is shutting down

// would change the six boxes on screen and leave everything else as it was. // // Older profiles have no copy; then the file stays untouched. +// +// Afterwards the controls are written into the file once more, and NOT the +// other way round. Until 2.1.1 the page was filled from the file again here, +// which went wrong in three ways: +// · the watched folder was filled along with it and lost its own options — +// a "keep the source" ticked there went out because a profile was loaded +// on another page; +// · a profile whose copy of the file disagreed with its own tick (see +// profileSettings) showed the tick for a moment and then took it back; +// · "shut down the PC when finished" came back from the copy, although it +// is deliberately not part of a profile. +// applyProfile has just set the controls to what the profile says. They are +// what the user sees, so they are what the file has to hold. async function applyProfileSettings(profile) { if (!profile || !profile.settings) return; try { const result = await api().ApplyProfile(profile.name); if (result && result.note) profileNote(result.note); + const shown = mirroredValues(); + if (Object.keys(shown).length) await api().SaveSettings(shown); // Read back: the window must show the file, not what we meant to write. refreshConfig(); - state.optionsSeeded = false; } catch (err) { profileNote("Settings not applied: " + err); } @@ -4672,8 +4724,11 @@

The PC is shutting down

const name = ($("opt-profile-name").value || $("opt-profile").value || "").trim(); if (!name) { profileNote("Type a name for these options first."); return; } // The INI copy goes into the profile, so it has to be at hand — the settings - // page may never have been opened in this session. - await ensureSettingsFile(); + // page may never have been opened in this session. And it has to be fresh: + // the list is read again unless unsaved edits are waiting on the settings + // page, which reading would throw away. + if (Object.keys(changedValues()).length === 0) await loadSettings(); + else await ensureSettingsFile(); try { state.profiles = (await api().SaveProfile(profileFromOptions(name))) || []; $("opt-profile").value = name; diff --git a/frontend/mirror_check.js b/frontend/mirror_check.js index c4affbf..f5a81e6 100644 --- a/frontend/mirror_check.js +++ b/frontend/mirror_check.js @@ -16,7 +16,7 @@ // 3. nothing is written for a key the file does not have. const { loadGui, createChecker } = require("./check_harness"); -const { gui, html, element, calls, setSettingsFileReply } = loadGui(); +const { gui, html, element, calls, setSettingsFileReply, setConfigReply } = loadGui(); const { check, finish } = createChecker(); // An INI that has everything, with values that differ from the window's own @@ -152,5 +152,52 @@ gui.ensureSettingsFile().then(() => { return gui.applyProfileSettings({ name: "Alt" }); }).then(() => { check("an old profile writes not ", calls.profileApplies.join(","), "Archiv"); + + console.log("\n=== a profile and its copy of the file agree ==="); + // Loading a profile reads the file back; from here on the Go side has to + // answer with the full file, as it would in the real window. + setConfigReply(fullConfig); + gui.applyConfig(fullConfig); + // The list of settings can be older than the boxes: here it still says + // keepSource=false while the box is ticked. Saved like that, the profile + // contradicted itself, and on loading the file's word took the tick away — + // originals were moved although "keep" had been saved. + setSettingsFileReply({ + found: true, + path: "X:\\tools\\NVENCForge_Config.ini", + note: "", + settings: [ + { key: "keepSource", value: "false" }, + { key: "autoCQTargetVMAF", value: "96" } + ] + }); + return gui.loadSettings(); +}).then(() => { + element("opt-keep").checked = true; + const profile = gui.profileFromOptions("Behalten"); + check("the tick is saved ", profile.keepSource, true); + check("and the copy says the same", profile.settings.keepSource, "true"); + check("other lines stay as read ", profile.settings.autoCQTargetVMAF, "96"); + // A key the list does not have is not invented on the way into a profile. + check("no line is invented ", "codec" in profile.settings, false); + + console.log("\n=== loading a profile leaves the watched folder alone ==="); + // The watched folder has its own options. The file says keepSource=true + // (fullConfig); the folder's own box is deliberately the opposite, so a page + // filled from the file again would show. + element("wopt-keep").checked = false; + element("wopt-codec").value = "h265"; + gui.applyProfile("opt", { name: "Wegräumen", keepSource: false, codec: "h265" }); + calls.settingSaves.length = 0; + return gui.applyProfileSettings({ name: "Wegräumen", settings: { keepSource: "true" } }); +}).then(() => { + // What the refresh after loading brings back from the Go side. + gui.applyConfig(fullConfig); + const written = calls.settingSaves[calls.settingSaves.length - 1] || {}; + check("the boxes go into the file", written.keepSource, "false"); + check(" the codec with them ", written.codec, "h265"); + check("the tick stays as loaded ", element("opt-keep").checked, false); + check("the folder keeps its tick ", element("wopt-keep").checked, false); + check(" and its codec ", element("wopt-codec").value, "h265"); finish(); }); diff --git a/watchfolder.go b/watchfolder.go index b82b990..fa7d833 100644 --- a/watchfolder.go +++ b/watchfolder.go @@ -224,6 +224,12 @@ func collectWatchCandidates(folder string) ([]watchCandidate, map[string]bool) { } if looksConverted(path) { finishedStems[watchStemKey(path)] = true + // Ein Ergebnis liegt in aller Regel nicht NEBEN seiner Quelle, + // sondern im Unterordner "output" — es zählt deshalb auch für den + // Ordner darüber. + if sourceKey, ok := watchSourceKeyOfOutput(path); ok { + finishedStems[sourceKey] = true + } return nil } info, statErr := entry.Info() @@ -253,6 +259,32 @@ func watchStemKey(path string) string { return strings.ToLower(filepath.Dir(path)) + string(filepath.Separator) + lower } +// watchOutputFolder ist der Unterordner, in den der Konverter seine Ergebnisse +// schreibt (NVENCForge: Converter.go, processFile). +const watchOutputFolder = "output" + +// watchSourceKeyOfOutput liefert für ein Ergebnis im Ordner "output" den +// Schlüssel, unter dem seine Quelle zu finden wäre: derselbe Namensstamm, aber +// im Ordner darüber. Liegt die Datei nicht in einem solchen Ordner, gibt es +// keinen. +// +// Bis 2.1.1 wurde nur im selben Ordner verglichen. Dort liegt ein Ergebnis +// aber nur, wenn der Konverter eine fertige Datei bloß umbenannt hat. Wer die +// Originale behält, bekam deshalb nach jedem Neustart des Fensters den ganzen +// Bestand noch einmal an den Konverter gereicht. +// +// Eine Grenze bleibt: Der Konverter räumt Dateinamen auf ("Film.WEB-DL.mkv" +// wird zu "Film.h265.mkv"). Solche Paare finden hier nicht zueinander — dann +// geht die Datei wie bisher an den Konverter, und der erkennt sein eigenes +// Ergebnis selbst und überspringt sie. +func watchSourceKeyOfOutput(path string) (string, bool) { + outputDir := filepath.Dir(path) + if !strings.EqualFold(filepath.Base(outputDir), watchOutputFolder) { + return "", false + } + return watchStemKey(filepath.Join(filepath.Dir(outputDir), filepath.Base(path))), true +} + // canBeOpened prüft, ob die Datei überhaupt lesbar ist. Hält ein Programm sie // noch exklusiv — manche Downloader tun das —, scheitert das Öffnen, und die // Datei ist erkennbar noch nicht fertig. diff --git a/watchfolder_test.go b/watchfolder_test.go index 6cd96e9..2c05332 100644 --- a/watchfolder_test.go +++ b/watchfolder_test.go @@ -125,6 +125,49 @@ func TestWatchSkipsWhatIsAlreadyDone(t *testing.T) { } } +// TestWatchKnowsResultsInTheOutputFolder: Der Konverter schreibt sein Ergebnis +// in den Unterordner "output". Wer die Originale behält, hat nach einem +// Neustart des Fensters Quelle und Ergebnis genau so liegen — und die Quelle +// darf dann nicht noch einmal gemeldet werden. Auch nicht, wenn das Ergebnis +// eine MP4 ist. +func TestWatchKnowsResultsInTheOutputFolder(t *testing.T) { + folder := t.TempDir() + writeWatchFile(t, filepath.Join(folder, "film.mkv"), 1000) + writeWatchFile(t, filepath.Join(folder, "output", "film.h265.mkv"), 400) + writeWatchFile(t, filepath.Join(folder, "serie", "folge.mp4"), 1000) + writeWatchFile(t, filepath.Join(folder, "serie", "Output", "folge.av1.mp4"), 400) + // Gleicher Name, aber in einem anderen Ordner: das Ergebnis oben gehört + // nicht zu dieser Datei. + writeWatchFile(t, filepath.Join(folder, "andere", "film.mkv"), 1000) + writeWatchFile(t, filepath.Join(folder, "neu.mkv"), 1000) + + watcher := newTestWatcher(folder) + start := time.Now() + watcher.scan(start) + found := names(watcher.scan(start.Add(watchQuietTime))) + + if len(found) != 2 || !found["neu.mkv"] || !found["film.mkv"] { + t.Fatalf("erwartet neu.mkv und film.mkv aus \"andere\", bekommen %v", found) + } + for _, item := range watcher.scan(start.Add(2 * watchQuietTime)) { + t.Errorf("nichts darf zweimal gemeldet werden, bekommen %s", item.Path) + } +} + +// TestWatchSourceKeyOfOutput prüft die Zuordnung selbst: nur was in einem +// "output"-Ordner liegt, gehört zu einer Quelle im Ordner darüber. +func TestWatchSourceKeyOfOutput(t *testing.T) { + root := filepath.Join("dl", "filme") + + key, ok := watchSourceKeyOfOutput(filepath.Join(root, "output", "Film.h265.mkv")) + if !ok || key != watchStemKey(filepath.Join(root, "film.mkv")) { + t.Errorf("Ergebnis im output-Ordner: Schlüssel %q (ok=%v) passt nicht zur Quelle", key, ok) + } + if _, ok := watchSourceKeyOfOutput(filepath.Join(root, "Film.h265.mkv")); ok { + t.Error("eine Datei außerhalb von output hat keine Quelle im Ordner darüber") + } +} + // TestWatchIgnoresNonVideoFiles: In einem Download-Ordner liegt alles Mögliche. func TestWatchIgnoresNonVideoFiles(t *testing.T) { folder := t.TempDir() From 8e27eb032b2b38bf5ec6cb7176bc00a0f5758a4a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 23:38:34 +0000 Subject: [PATCH 2/2] Release 2.1.2: the "keep the source" tick stays where you put it Version 2.1.2 in main.go and wails.json, and the release text. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01GvUq7F6HRPWfTUBjDkD1bR --- .github/release-notes/v2.1.2.md | 12 ++++++++++++ main.go | 2 +- wails.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .github/release-notes/v2.1.2.md diff --git a/.github/release-notes/v2.1.2.md b/.github/release-notes/v2.1.2.md new file mode 100644 index 0000000..b59ec08 --- /dev/null +++ b/.github/release-notes/v2.1.2.md @@ -0,0 +1,12 @@ +## NVENCForgeGUI 2.1.2: the "keep the source" tick stays where you put it + +This release fixes three places where the window and your files could end up disagreeing about whether originals are kept. + +- **Loading a profile no longer changes the watched folder.** Picking a profile on the Convert page used to fill the watched folder's options from the file as well. A "Keep the source file where it is" ticked there went out unnoticed, and the next video it found was moved away. The watched folder now keeps its own options, as its page always said. +- **A profile no longer contradicts itself.** A profile saved while unsaved edits were waiting on the Settings page could carry a tick and a copy of the INI that said the opposite. On loading, the tick showed for a moment and was taken back. Now what the boxes show is what is saved, and what is loaded is what goes into the INI. +- **"Shut down the PC when finished" does not come back with a profile.** It was never meant to be part of one. +- **The watched folder recognises finished results in `output`.** With originals kept, every restart of the window handed the whole folder to the converter again. + +Best together with NVENCForge 2.2.3, which stops `-keep` from renaming originals: use the converter's update button. + +Update: About page > *Check for updates*, or replace `NVENCForgeGUI.exe` with the new one. Your converter, settings and profiles in `tools` stay. diff --git a/main.go b/main.go index 5bd22ec..8de8674 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ var assets embed.FS // guiVersion ist die einzige Stelle, an der die Version dieses Fensters // steht. Angezeigt wird sie im Fensterkopf (Titelleiste) und in der // Kopfzeile der Oberfläche selbst (siehe StartupInfo in app.go). -const guiVersion = "2.1.1" +const guiVersion = "2.1.2" // singleInstanceID hält die Startsperre. Der Name muss auf dem Rechner // einmalig sein und darf sich nie ändern — sonst erkennt eine neue Ausgabe die diff --git a/wails.json b/wails.json index 8f8e2dd..4e372c1 100644 --- a/wails.json +++ b/wails.json @@ -8,7 +8,7 @@ "info": { "companyName": "burnersen", "productName": "NVENCForgeGUI", - "productVersion": "2.1.1", + "productVersion": "2.1.2", "copyright": "Copyright 2026 burnersen", "comments": "A window for NVENCForge" }