diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 5990ab296dce..def5e312206f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -538,15 +538,15 @@ public final class UpdateChecker { } public static String getInstallationUID(final PropertiesComponent propertiesComponent) { - String uid = ""; + if (SystemInfo.isWindows) { + String uid = getInstallationUIDOnWindows(propertiesComponent); + if (uid != null) { + return uid; + } + } + String uid; if (!propertiesComponent.isValueSet(INSTALLATION_UID)) { - try { - uid = UUID.randomUUID().toString(); - } - catch (Exception ignored) { - } - catch (InternalError ignored) { - } + uid = generateUUID(); propertiesComponent.setValue(INSTALLATION_UID, uid); } else { @@ -555,6 +555,46 @@ public final class UpdateChecker { return uid; } + @Nullable + private static String getInstallationUIDOnWindows(PropertiesComponent propertiesComponent) { + String appdata = System.getenv("APPDATA"); + if (appdata != null) { + File jetBrainsDir = new File(appdata, "JetBrains"); + if (jetBrainsDir.exists() || jetBrainsDir.mkdirs()) { + File permanentIdFile = new File(jetBrainsDir, "PermanentUserId"); + try { + if (permanentIdFile.exists()) { + return FileUtil.loadFile(permanentIdFile).trim(); + } + String uuid; + if (propertiesComponent.isValueSet(INSTALLATION_UID)) { + uuid = propertiesComponent.getValue(INSTALLATION_UID); + } + else { + uuid = generateUUID(); + } + FileUtil.writeToFile(permanentIdFile, uuid); + return uuid; + } + catch (IOException e) { + // ignore + } + } + } + return null; + } + + private static String generateUUID() { + try { + return UUID.randomUUID().toString(); + } + catch (Exception ignored) { + } + catch (InternalError ignored) { + } + return ""; + } + public static boolean install(List downloaders) { boolean installed = false; for (PluginDownloader downloader : downloaders) {