Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Update version number in Add/Remove Programs on update #4454

Closed
dstillman opened this issue Nov 4, 2019 · 7 comments
Closed

Windows: Update version number in Add/Remove Programs on update #4454

dstillman opened this issue Nov 4, 2019 · 7 comments
Assignees

Comments

@dstillman
Copy link
Member

dstillman commented Nov 4, 2019

https://forums.zotero.org/discussion/79866/zotero-updater-not-changing-version-number-in-add-or-remove-programs

(Firefox now does this. We should see what they're doing to change a key in the registry.)

@dstillman
Copy link
Member Author

dstillman commented Nov 25, 2021

It looks like we'd need to update DisplayVersion in HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Zotero 5.0.96.2 (x86 en-US) (as long as we're a 32-bit app).

Mozilla seems to do this with the maintenance service, which doesn't help us:

https://searchfox.org/mozilla-central/rev/ac7a567f036e1954542763f4722fbfce041fb752/toolkit/components/maintenanceservice/serviceinstall.cpp#460

https://searchfox.org/mozilla-central/rev/ac7a567f036e1954542763f4722fbfce041fb752/toolkit/components/maintenanceservice/serviceinstall.cpp#31-43

But we could theoretically do this with nsIWindowsRegKey without messing with our updater:

http://udn.realityripple.com/docs/Mozilla/Tech/XPCOM/Accessing_the_Windows_Registry_Using_XPCOm

I guess we could do it on startup when the current DisplayVersion didn't match the current app version. (If so, this would belong in zotero/zotero.)

@adomasven
Copy link
Member

But we could theoretically do this with nsIWindowsRegKey without messing with our updater:

We have some example code using this https://github.com/zotero/zotero-word-for-windows-integration/blob/master/resource/installer.jsm#L75

@dpprdan
Copy link

dpprdan commented Nov 25, 2021

I guess we could do it on startup

Just a minor point, but is there an easy way to make the update happen directly after installation? If the auto-update happens without a restart, the installed and reported-by-ARP versions are out of sync until the next restart.

@dstillman
Copy link
Member Author

Updates happen on restart, so the new version always starts up immediately.

@dstillman dstillman transferred this issue from zotero/zotero-standalone-build Jul 29, 2024
@dstillman
Copy link
Member Author

dstillman commented Jul 29, 2024

Except we can't actually do this in the app itself, because writing to HKLM requires administrative privileges…

Otherwise code like this would work:

var version = Zotero.version;
var arch = Zotero.arch;
if (arch == 'aarch64') {
	arch = 'ARM64';
}
else if (arch == 'x86_64') {
	arch = 'x64';
}
else if (arch == 'i386') {
	arch = 'x86';
}
var versionString = `${version} (${arch})`;

var appDir = FileUtils.getDir('GreBinD', []).path;
var wrk = Components.classes["@mozilla.org/windows-registry-key;1"]
	.createInstance(Components.interfaces.nsIWindowsRegKey);
wrk.open(
	Components.interfaces.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
		"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
		Components.interfaces.nsIWindowsRegKey.ACCESS_READ
);
try {
	let i = wrk.childCount - 1;
	for (let i = wrk.childCount - 1; i >= 0; i--) {
		let name = wrk.getChildName(i);
		if (!name.startsWith(Zotero.appName)) continue;
		let child = wrk.openChild(
			name,
			Components.interfaces.nsIWindowsRegKey.ACCESS_READ
				| Components.interfaces.nsIWindowsRegKey.ACCESS_WRITE
		);
		try {
			let installLocation = child.readStringValue('InstallLocation');
			if (installLocation == appDir) {
				child.writeStringValue('DisplayVersion', versionString);
			}
		}
		finally {
			child.close();
		}
	}
}
finally {
	wrk.close();
}

But it just throws NS_ERROR_FAILURE if ACCESS_WRITE is used.

So I think we'd have to patch the updater itself to update the registry key, borrowing code from the Mozilla Maintenance Service.

@dstillman
Copy link
Member Author

Actually, the linked code above is just for the Maintenance Service to update its own entry. For Firefox itself it's handled via the uninstaller's helper.exe with a /PostUpdate switch. I'll look into why that's not working for us.

@dstillman dstillman self-assigned this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants