Forked from mreyesv/JetbrainsEvaluationReset_2020.py
Created
February 16, 2021 04:19
-
-
Save walteranyika/870ae7b1ed31d3e9c2ac77e107e2cfd1 to your computer and use it in GitHub Desktop.
[Activate] A Python Script To Reset The Evaluation License Of These Jetbrains Products Released In 2020 Or Later (IntelliJIdea, CLion, Rider, PyCharm, RubyMine, GoLand )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reset Jetbrains 2020 Products | |
import glob | |
import os | |
import winreg | |
from os import path | |
from os.path import expanduser | |
home = expanduser("~") | |
newJetbrainsHome = path.join(home, "AppData\Roaming\JetBrains") | |
class JetbrainsProduct: | |
def __init__(self, name, longName, shortName): | |
self.name = name | |
self.longName = longName | |
self.shortName = shortName | |
def returnOrEmpty(pathResult): | |
return "" if len(pathResult) == 0 else pathResult[0] | |
class ProductFile: | |
def __init__(self, absolutePath, productObject): | |
self.absolutepath = absolutePath | |
self.productObject = productObject | |
def getEvaluationLicensePath(self): | |
return returnOrEmpty(glob.glob(path.join(self.absolutepath, "eval\*evaluation.key"))) | |
def getOtherFilePath(self): | |
return returnOrEmpty(glob.glob(path.join(self.absolutepath, "options\other.xml"))) | |
def getProductObject(self): | |
return self.productObject | |
def deleteSubkey(hkey, key): | |
open_key = winreg.OpenKey(hkey, key, 0, winreg.KEY_ALL_ACCESS) | |
info_key = winreg.QueryInfoKey(open_key) | |
for x in range(0, info_key[0]): | |
sub_key = winreg.EnumKey(open_key, 0) | |
try: | |
winreg.DeleteKey(open_key, sub_key) | |
print("Removed %s\\%s " % (key, sub_key)) | |
except WindowsError: | |
deleteSubkey(hkey, f"{key}\\{sub_key}") | |
print("") | |
winreg.DeleteKey(open_key, "") | |
open_key.Close() | |
print("Removed %s" % key) | |
def removeRegistry(selectedProduct): | |
print("Removing Registry Files ...") | |
key = f"Software\JavaSoft\Prefs\jetbrains\\{selectedProduct.shortName}" | |
print("Removing " + key + " from registry") | |
try: | |
deleteSubkey(winreg.HKEY_CURRENT_USER, key) | |
except WindowsError as e: | |
print("Are you sure you ran this script as an administrator?") | |
print("Are you sure you didn't remove the registry already?") | |
print(str(e)) | |
else: | |
print("Registry edited") | |
print() | |
def getAllSupportedProducts(): | |
# creating supported jetbrains products | |
intellij = JetbrainsProduct("IntelliJIdea", "IntelliJIdea", "idea") | |
clion = JetbrainsProduct("CLion", "CLion", "clion") | |
rider = JetbrainsProduct("Rider", "Rider", "rider") | |
pycharm = JetbrainsProduct("PyCharm", "PyCharm", "pycharm") | |
rubymine = JetbrainsProduct("RubyMine", "RubyMine", "rubymine") | |
goland = JetbrainsProduct("GoLand", "GoLand", "goland") | |
supportedJetbrainsProducts = (pycharm, intellij, clion, rider, rubymine, goland) | |
return supportedJetbrainsProducts | |
def displayAllInstalledVersions(selectedProduct, findInstalledVersionsResult): | |
numberOfInstalledVersions = len(findInstalledVersionsResult) | |
print(f"Found {numberOfInstalledVersions} versions of {selectedProduct.name} : ") | |
for i in range(numberOfInstalledVersions): | |
print(str(i) + ": " + findInstalledVersionsResult[i]) | |
def readProductFromUser(supportedJetbrainsProducts): | |
print("Jetbrains Activator v2.0 ") | |
numberOfSupportedProducts = len(supportedJetbrainsProducts) | |
for i in range(numberOfSupportedProducts): | |
print(f"{i} : {supportedJetbrainsProducts[i].name}") | |
while True: | |
print("choice :", end=" ") | |
selectedProductIndex = int(input()) | |
isValidProductIndex = numberOfSupportedProducts > selectedProductIndex >= 0 | |
if isValidProductIndex: | |
selectedProduct = supportedJetbrainsProducts[selectedProductIndex] | |
break | |
print(f"You Selected : {selectedProduct.name}") | |
print() | |
return selectedProduct | |
def isEmpty(text): | |
return text == '' | |
def readProductVersionFromUser(installedVersionsResult): | |
numberOfInstalledVersions = len(installedVersionsResult) | |
while True: | |
print("choice (by default 0):", end=" ") | |
versionIndex = input() | |
if isEmpty(versionIndex): | |
versionIndex = 0 | |
versionIndex = int(versionIndex) | |
isValidVersionIndex = 0 <= versionIndex < numberOfInstalledVersions | |
if isValidVersionIndex: | |
break | |
print() | |
return versionIndex | |
def startWith(text): | |
return text + "*" | |
def findAllInstalledVersionsOf(product): | |
return glob.glob(path.join(newJetbrainsHome, startWith(product.longName))) | |
def removeEvaluationLicenseFile(productFile: ProductFile): | |
print("Removing evaluation license file...") | |
evaluationFilePath = "" | |
try: | |
evaluationFilePath = productFile.getEvaluationLicensePath() | |
except IndexError: | |
print("evaluation license not found") | |
print("You must start an evaluation license before using the script") | |
if not isEmpty(evaluationFilePath): | |
os.remove(evaluationFilePath) | |
print("License Removed.\n") | |
else: | |
print() | |
def clearEvlsprtInOtherFile(productFile: ProductFile): | |
print("removing lines which containing evlsprt...") | |
otherXml = productFile.getOtherFilePath() | |
print("Clearing evlsprt in " + otherXml) | |
print("Removing...") | |
# reading other.xml | |
with open(otherXml, 'r') as file: | |
data = file.read() | |
# editing | |
data = data.split("\n") | |
newFile = '' | |
for i in range(len(data)): | |
if data[i].find("evlsprt") != -1: | |
print(data[i]) | |
else: | |
newFile += f"{data[i]}\n" | |
# saving edited other.xml | |
with open(otherXml, "w") as file: | |
file.write(newFile) | |
print() | |
def resetEvaluationOnWindows(productFile: ProductFile): | |
print("System: Windows") | |
removeRegistry(productFile.getProductObject()) | |
removeEvaluationLicenseFile(productFile) | |
clearEvlsprtInOtherFile(productFile) | |
def resetEvaluationOnLinux(): | |
print(f"still under construction") | |
selectedProduct = readProductFromUser(getAllSupportedProducts()) | |
allInstalledVersionsOfProduct = findAllInstalledVersionsOf(selectedProduct) | |
displayAllInstalledVersions(selectedProduct, allInstalledVersionsOfProduct) | |
selectedProductVersionIndex = readProductVersionFromUser(allInstalledVersionsOfProduct) | |
selectedProductFile = ProductFile(allInstalledVersionsOfProduct[selectedProductVersionIndex], selectedProduct) | |
if os.name == "nt": | |
resetEvaluationOnWindows(selectedProductFile) | |
elif os.name == "posix": | |
resetEvaluationOnLinux() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment