import os #line:1
from base64 import b16decode as dec #line:2
from uuid import getnode as getnode #line:3
import c4d #line:4
from ssp_utils_dialog import *#line:5
from ssp_ids import *#line:6
from ssp_utils_pref import *#line:7
PLUGIN_ID_AUTH_REQUESTER =1057823 #line:12
IDC_SERIAL =41001 #line:15
IDC_SERIAL_COPY =41008 #line:16
IDC_SUBMIT =41002 #line:17
IDC_CANCEL =41003 #line:18
IDC_CODEBOX =41004 #line:19
IDC_CODEBOX_AUTH =41005 #line:20
IDC_PASTESERIAL =41007 #line:21
A_CODE =b'43344431'#line:23
P_CODE =b'433444544142533132'#line:24
SK =b'313258'#line:26
NO_MAC =b'363932'#line:27
if c4d .GetC4DVersion ()//1000 >=23 :#line:30
    fd =dec #line:31
else :#line:33
    fd =lambda O0OOOO0O0O0OO0OOO :'b_'+dec (O0OOOO0O0O0OO0OOO )+'_'#line:34
def GetAC ():#line:37
    OOO0000OO00OOO0O0 =''#line:38
    OOOO00O0000OOOOO0 =lambda OOO0O000OOO00OOO0 :('#'+str (fd (OOO0O000OOO00OOO0 ))+'_')[3 :-2 ]#line:39
    O00OO0O000O00OO0O =fd #line:40
    O000OOOOOO0000000 =lambda O00O00O0000000OOO :str (fd (O00O00O0000000OOO ))[2 :-1 ]#line:41
    try :#line:42
        OOO0O0000OOO00OOO =str (getnode ())#line:43
        OO0OO0OOO00O0OO00 =OOO0O0000OOO00OOO [-3 :]#line:44
        OOO00O0O0O0O0O000 =OOOO00O0000OOOOO0 (A_CODE )+OO0OO0OOO00O0OO00 +O000OOOOOO0000000 (P_CODE )#line:45
    except :#line:47
        OO0OO0OOO00O0OO00 =str (O00OO0O000O00OO0O (NO_MAC ))[2 :-1 ]#line:48
        O000OOOOOO0000000 =OOOO00O0000OOOOO0 #line:49
        OOO00O0O0O0O0O000 =O000OOOOOO0000000 (A_CODE )+OO0OO0OOO00O0OO00 +O000OOOOOO0000000 (P_CODE )#line:50
    O0O0O000OO0O00O00 =GetWorldPrefs ()#line:52
    O0O0O000OO0O00O00 .SetString (BCID_B ,OOO00O0O0O0O0O000 )#line:53
    return OOO00O0O0O0O0O000 #line:55
def VerSC (OOOOO00OO0OOO00O0 ):#line:58
    O0O0O000O0O00000O =lambda O00OOOO0O0O00O000 :('_'+str (fd (O00OOOO0O0O00O000 ))+'***')[3 :-4 ]#line:59
    OOOOO00OO0OOO00O0 =OOOOO00OO0OOO00O0 .replace (' ','')#line:61
    O000OOO0O0OOO0000 =GetAC ()[3 :6 ]#line:63
    OOOO0OOOOO00OO000 =OOOOO00OO0OOO00O0 [1 :4 ]#line:64
    OO000O0OO0O0O0O00 =O0O0O000O0O00000O (SK )#line:65
    if O000OOO0O0OOO0000 ==OOOO0OOOOO00OO000 and OO000O0OO0O0O0O00 in OOOOO00OO0OOO00O0 :#line:67
        return True #line:68
    else :#line:70
        return False #line:71
def TestAuth ():#line:74
    OO0OOOO0O00O0OOO0 =GetWorldPrefs ()#line:75
    O00OOO0O0OO000O0O =OO0OOOO0O00O0OOO0 .GetString (BCID_A )#line:77
    if O00OOO0O0OO000O0O is not None :#line:78
        if VerSC (str (O00OOO0O0OO000O0O )):#line:79
            c4d .SpecialEventAdd (PLUGIN_ID_COREMESSAGE_2 )#line:80
            return True #line:81
    return False #line:83
def SetAuth (O0O000O00O00O00O0 ):#line:86
    OO0O00O00OO000O00 =GetWorldPrefs ()#line:87
    OO0O00O00OO000O00 .SetString (BCID_A ,O0O000O00O00O00O0 )#line:88
def Auth ():#line:91
    if TestAuth ():#line:92
        return True #line:93
    print ('3DtoAll: {0} - Activation Needed'.format (PLUGIN_NAME ))#line:95
    O000000O0O0OO0O00 =AuthDialog ()#line:97
    O000000O0O0OO0O00 .Open (c4d .DLG_TYPE_MODAL ,pluginid =PLUGIN_ID_AUTH_REQUESTER ,xpos =-2 ,ypos =-2 )#line:98
    return TestAuth ()#line:100
class AuthDialog (c4d .gui .GeDialog ):#line:103
    def CreateLayout (OO00O0O00O0O0000O ):#line:105
        OO00O0O00O0O0000O .SetTitle ('{0} - Activation'.format (PLUGIN_NAME ))#line:106
        if OO00O0O00O0O0000O .GroupBegin (0 ,c4d .BFH_SCALEFIT ,1 ,title ='Registration'):#line:108
            OO00O0O00O0O0000O .GroupBorderSpace (5 ,0 ,5 ,5 )#line:109
            O0O000OOOO0OO00O0 =LoadImage ('logo_about',suffix ='.jpg')#line:111
            CreateLayoutAddBitmap (OO00O0O00O0O0000O ,O0O000OOOO0OO00O0 ,border =c4d .BORDER_ROUND )#line:112
            OO00O0O00O0O0000O .AddStaticText (0 ,c4d .BFH_CENTER ,name ='Your Code:')#line:114
            if OO00O0O00O0O0000O .GroupBegin (0 ,c4d .BFH_CENTER ,cols =2 ):#line:116
                OO00O0O00O0O0000O .GroupBorderNoTitle (c4d .BORDER_THIN_OUT )#line:117
                OO00O0O00O0O0000O .GroupBorderSpace (20 ,5 ,20 ,5 )#line:118
                OO00O0O00O0O0000O .AddStaticText (IDC_CODEBOX_AUTH ,c4d .BFH_CENTER ,initw =180 ,inith =20 ,borderstyle =c4d .BORDER_IN )#line:120
                OO00O0O00O0O0000O .AddButton (IDC_SERIAL_COPY ,c4d .BFH_CENTER ,initw =60 ,inith =15 ,name ="Copy")#line:121
            OO00O0O00O0O0000O .GroupEnd ()#line:123
            OO00O0O00O0O0000O .AddButton (IDC_SERIAL ,c4d .BFH_CENTER ,initw =250 ,inith =20 ,name ="Get Activation Serial")#line:125
            if OO00O0O00O0O0000O .GroupBegin (0 ,c4d .BFH_CENTER |c4d .BFV_TOP ,rows =1 ,initw =450 ):#line:127
                OO00O0O00O0O0000O .GroupBorderSpace (0 ,10 ,0 ,0 )#line:128
                OO00O0O00O0O0000O .AddSeparatorV (0 ,c4d .BFH_SCALEFIT )#line:130
                OO00O0O00O0O0000O .AddStaticText (0 ,c4d .BFH_CENTER ,name ='{0} - Activation Serial:'.format (PLUGIN_NAME ))#line:131
                OO00O0O00O0O0000O .AddSeparatorV (0 ,c4d .BFH_SCALEFIT )#line:132
            OO00O0O00O0O0000O .GroupEnd ()#line:134
            if OO00O0O00O0O0000O .GroupBegin (0 ,c4d .BFV_TOP ,cols =2 ):#line:136
                OO00O0O00O0O0000O .GroupBorderNoTitle (c4d .BORDER_ACTIVE_4 )#line:137
                OO00O0O00O0O0000O .GroupBorderSpace (5 ,5 ,3 ,5 )#line:138
                OO00O0O00O0O0000O .AddButton (IDC_PASTESERIAL ,c4d .BFH_CENTER ,initw =40 ,inith =60 ,name ="Paste")#line:140
                OO00O0O00O0O0000O .AddEditText (IDC_CODEBOX ,c4d .BFH_CENTER ,initw =410 ,inith =60 ,editflags =c4d .EDITTEXT_HELPTEXT )#line:142
            OO00O0O00O0O0000O .GroupEnd ()#line:144
            OO00O0O00O0O0000O .AddButton (IDC_SUBMIT ,c4d .BFH_CENTER ,initw =150 ,inith =30 ,name ="SUBMIT")#line:146
        OO00O0O00O0O0000O .GroupEnd ()#line:148
        OO00O0O00O0O0000O .AddSeparatorH (0 ,c4d .BFH_SCALEFIT )#line:150
        OO00O0O00O0O0000O .AddStaticText (0 ,c4d .BFH_CENTER ,0 ,0 ,name ='(c) 2021. 3DtoAll. All Rights Reserved.')#line:152
        return True #line:154
    def InitValues (OO0O000OOO0OO00OO ):#line:157
        OO0O000OOO0OO00OO .SetString (IDC_CODEBOX_AUTH ,GetAC ())#line:158
        OO0O000OOO0OO00OO .SetString (IDC_CODEBOX ,'Enter your Activation Serial here.',flags =c4d .EDITTEXT_HELPTEXT )#line:159
        OO0O000OOO0OO00OO .SetString (IDC_CODEBOX ,'')#line:160
        return True #line:161
    def Command (OOO00O0OOO00O0OOO ,OO0OOO000OO00O00O ,O0O0O0O00O0O000OO ):#line:164
        if OO0OOO000OO00O00O ==IDC_PASTESERIAL :#line:166
            OOO0O0OOO0OOOOO0O =c4d .GetStringFromClipboard ()#line:167
            if OOO0O0OOO0OOOOO0O !=None :#line:169
                OOO00O0OOO00O0OOO .SetString (IDC_CODEBOX ,OOO0O0OOO0OOOOO0O )#line:170
        elif OO0OOO000OO00O00O ==IDC_SERIAL_COPY :#line:172
            c4d .CopyStringToClipboard (OOO00O0OOO00O0OOO .GetString (IDC_CODEBOX_AUTH ))#line:173
        elif OO0OOO000OO00O00O ==IDC_SERIAL :#line:176
            O0O0000OOOOOO0O00 =URL_3DTOALL +'/register'#line:177
            c4d .storage .GeExecuteFile (O0O0000OOOOOO0O00 )#line:178
        elif OO0OOO000OO00O00O ==IDC_SUBMIT :#line:180
            O000O0OOO0000O00O =False #line:181
            OOOO000OO0000O0OO =OOO00O0OOO00O0OOO .GetString (IDC_CODEBOX )#line:183
            if VerSC (OOOO000OO0000O0OO ):#line:185
                SetAuth (OOOO000OO0000O0OO )#line:186
                O000O0OOO0000O00O =True #line:187
            if O000O0OOO0000O00O :#line:189
                c4d .gui .MessageDialog ('{0}: Plugin Authorization successful!'.format (PLUGIN_NAME ))#line:190
                OOO00O0OOO00O0OOO .Close ()#line:191
            else :#line:193
                c4d .gui .MessageDialog ('{0}: Wrong Serial or for different/older version.'.format (PLUGIN_NAME ))#line:194
        elif OO0OOO000OO00O00O ==IDC_CANCEL :#line:196
            OOO00O0OOO00O0OOO .Close ()#line:197
        return True #line:199
