Created
March 10, 2020 17:00
-
-
Save HoussemNasri/82cf27d834475c4a994899807427cdf3 to your computer and use it in GitHub Desktop.
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
import glob | |
import os | |
import sys | |
from os import path | |
from os.path import expanduser | |
# CLion Activator v1.2 | |
# By congard | |
# https://github.com/congard | |
# http://congard.pp.ua/support-me | |
# mailto:dbcongard@gmail.com | |
# https://t.me/congard | |
# If you have an opportunity, please buy CLion: https://www.jetbrains.com/clion/buy/ | |
home = expanduser("~") | |
# searching CLion folder | |
ideaPath = glob.glob(path.join(home, ".IntelliJIdea*")) | |
print("Found Intellij folders:", *ideaPath, ' ') | |
print("Enter folder index (by default 0):") | |
print("Found " + str(len(ideaPath)) + " of Intellij : ") | |
for i in range(len(ideaPath)): | |
print(str(i) + ": " + ideaPath[i]) | |
while True: | |
print("choice (by default 0):", end=" ") | |
# you can specify default Intellij Version folder by passing command-line argument - folder index | |
if len(sys.argv) > 1: | |
index = sys.argv[1] | |
print(index) | |
else: | |
index = input() | |
if index == '': | |
index = 0 | |
index = int(index) | |
if 0 <= index < len(ideaPath): | |
break | |
print("You should enter a value between 0 and " + str(len(ideaPath) - 1)) | |
# removing evaluation key | |
try: | |
key = glob.glob(path.join(ideaPath[index], "config/eval/idea*evaluation.key"))[0] | |
except IndexError: | |
print("evaluation license not found") | |
print("You must start an evaluation license before using the script") | |
exit(0) | |
print("Removing " + key) | |
os.remove(key) | |
# removing line which containing evlsprt | |
otherXml = path.join(ideaPath[index], "config/options/other.xml") | |
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 += data[i] + "\n" | |
# saving edited other.xml | |
with open(otherXml, "w") as file: | |
file.write(newFile) | |
# Removing the following entries for Windows and Linux is different. | |
# On Linux, they are stored simply in /home, on Windows, in the registry. | |
# IN WINDOWS YOU SHOULD LAUNCH THIS SCRIPT AS AN ADMINISTRATOR! | |
# removing clion userPrefs directory for linux | |
# i didnt edit it because i dont have linux | |
if os.name == "posix": | |
print("System: Linux") | |
import shutil | |
clionUserPrefs = path.join(home, ".java/.userPrefs/jetbrains/clion") | |
print("Removing " + clionUserPrefs) | |
shutil.rmtree(clionUserPrefs) | |
# removing registry entries for windows | |
if os.name == "nt": | |
print("System: Windows") | |
import winreg | |
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, key + "\\" + sub_key) | |
winreg.DeleteKey(open_key, "") | |
open_key.Close() | |
print("Removed %s" % key) | |
key = R"Software\JavaSoft\Prefs\jetbrains\idea" | |
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(str(e)) | |
else: | |
print("Registry edited") |
@LurisHu run the script as administrator on your windows machine and do what it says, but keep in mind this script doesn't work with IntellijIdea 2020 and later, I have another one that works but I didn't publish it for several reasons, if you need it just ask.
Can you share one for 2020 and later?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use?