Skip to content

Commit 3a5925f

Browse files
committed
[[ LicenseClass ]] Reuse license class <-> string conversions
This patch moves license class to string conversion to inline functions of license.h to simplify maintenance. It also adds the `communityplus` `editionType` string.
1 parent c14b9f0 commit 3a5925f

File tree

6 files changed

+71
-80
lines changed

6 files changed

+71
-80
lines changed

engine/src/deploy.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,7 @@ void MCIdeDeploy::exec_ctxt(MCExecContext& ctxt)
801801

802802
// If the banner_class field is set and we are not a trial license, we
803803
// override the license class with that specified.
804-
uint32_t t_license_class;
805-
t_license_class = kMCLicenseClassNone;
804+
MCLicenseClass t_license_class = kMCLicenseClassNone;
806805
if (MClicenseparameters . license_class == kMCLicenseClassCommercial)
807806
{
808807
// If we have a commercial license, then we only allow a commercial

engine/src/deploy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct MCDeployParameters
111111

112112
// This can be set to commercial or professional trial. In that
113113
// case, the standalone will be built in that mode.
114-
uint32_t banner_class;
114+
MCLicenseClass banner_class;
115115

116116
// The timeout for the banner that's displayed before startup.
117117
uint32_t banner_timeout;

engine/src/exec-engine.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5050

5151
#include "libscript/script.h"
5252

53+
#include "license.h"
54+
5355
////////////////////////////////////////////////////////////////////////////////
5456

5557
MC_EXEC_DEFINE_EVAL_METHOD(Engine, Version, 1)
@@ -2063,32 +2065,12 @@ void MCEngineEvalSHA1Uuid(MCExecContext& ctxt, MCStringRef p_namespace_id, MCStr
20632065

20642066
void MCEngineGetEditionType(MCExecContext& ctxt, MCStringRef& r_edition)
20652067
{
2066-
bool t_success;
2067-
switch (MClicenseparameters.license_class)
2068+
if (!MCStringFromLicenseClass(MClicenseparameters.license_class,
2069+
true,
2070+
r_edition))
20682071
{
2069-
case kMCLicenseClassCommunity:
2070-
t_success = MCStringCreateWithCString("community", r_edition);
2071-
break;
2072-
2073-
case kMCLicenseClassEvaluation:
2074-
case kMCLicenseClassCommercial:
2075-
t_success = MCStringCreateWithCString("commercial", r_edition);
2076-
break;
2077-
2078-
case kMCLicenseClassProfessionalEvaluation:
2079-
case kMCLicenseClassProfessional:
2080-
t_success = MCStringCreateWithCString("professional", r_edition);
2081-
break;
2082-
2083-
default:
2084-
t_success = false;
2085-
break;
2072+
ctxt . Throw();
20862073
}
2087-
2088-
if (t_success)
2089-
return;
2090-
2091-
ctxt . Throw();
20922074
}
20932075

20942076
////////////////////////////////////////////////////////////////////////////////

engine/src/license.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct MCLicenseParameters
6363
MCStringRef license_token;
6464
MCStringRef license_name;
6565
MCStringRef license_organization;
66-
uint32_t license_class;
66+
MCLicenseClass license_class;
6767
uint4 license_multiplicity;
6868

6969
uint4 script_limit;
@@ -79,4 +79,51 @@ struct MCLicenseParameters
7979
extern MCLicenseParameters MClicenseparameters;
8080
extern Boolean MCenvironmentactive;
8181

82+
static const struct { const char *tag; MCLicenseClass value; } s_class_map[] =
83+
{
84+
{ "community", kMCLicenseClassCommunity },
85+
{ "communityplus", kMCLicenseClassCommunityPlus },
86+
{ "evaluation", kMCLicenseClassEvaluation },
87+
{ "commercial", kMCLicenseClassCommercial },
88+
{ "professional evaluation", kMCLicenseClassProfessionalEvaluation },
89+
{ "professional", kMCLicenseClassProfessional },
90+
{ "", kMCLicenseClassNone }
91+
};
92+
93+
inline bool MCStringToLicenseClass(MCStringRef p_class, MCLicenseClass &r_class)
94+
{
95+
for(uindex_t t_index = 0; t_index < sizeof(s_class_map) / sizeof(s_class_map[0]); ++t_index)
96+
{
97+
if (MCStringIsEqualToCString(p_class, s_class_map[t_index].tag, kMCCompareCaseless))
98+
{
99+
r_class = s_class_map[t_index].value;
100+
return true;
101+
}
102+
}
103+
104+
return false;
105+
}
106+
107+
inline bool MCStringFromLicenseClass(MCLicenseClass p_class, bool p_simplified, MCStringRef &r_class)
108+
{
109+
if (p_simplified && p_class == kMCLicenseClassEvaluation)
110+
{
111+
p_class = kMCLicenseClassCommercial;
112+
}
113+
else if (p_simplified && p_class == kMCLicenseClassProfessionalEvaluation)
114+
{
115+
p_class = kMCLicenseClassProfessional;
116+
}
117+
118+
for(uindex_t t_index = 0; t_index < sizeof(s_class_map) / sizeof(s_class_map[0]); ++t_index)
119+
{
120+
if (s_class_map[t_index].value == p_class)
121+
{
122+
return MCStringCreateWithCString(s_class_map[t_index].tag, r_class);
123+
}
124+
}
125+
126+
return false;
127+
}
128+
82129
#endif

engine/src/lnxstack.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,16 @@ void MCStack::sethints()
295295
|| t_env == kMCModeEnvironmentTypeInstaller
296296
|| t_env == kMCModeEnvironmentTypeServer)
297297
{
298-
const char *t_edition_name;
299-
switch (MClicenseparameters.license_class)
300-
{
301-
case kMCLicenseClassProfessionalEvaluation:
302-
case kMCLicenseClassProfessional:
303-
t_edition_name = "business";
304-
break;
305-
case kMCLicenseClassEvaluation:
306-
case kMCLicenseClassCommercial:
307-
t_edition_name = "indy";
308-
break;
309-
case kMCLicenseClassNone:
310-
case kMCLicenseClassCommunity:
311-
default:
312-
t_edition_name = "community";
313-
break;
314-
}
315-
316-
if (MCStringCreateMutable(0, &t_app_name))
298+
299+
MCAutoStringRef t_edition_name;
300+
if (MCStringCreateMutable(0, &t_app_name) &&
301+
MCStringFromLicenseClass(MClicenseparameters.license_class, true, &t_edition_name))
317302
{
318303
bool t_success = true;
319304
if (t_env == kMCModeEnvironmentTypeEditor)
320-
t_success = MCStringAppendFormat(*t_app_name, "%s%s_%s", MCapplicationstring, t_edition_name, MC_BUILD_ENGINE_SHORT_VERSION);
305+
t_success = MCStringAppendFormat(*t_app_name, "%s%@_%s", MCapplicationstring, *t_edition_name, MC_BUILD_ENGINE_SHORT_VERSION);
321306
else
322-
t_success = MCStringAppendFormat(*t_app_name, "%s%s_%@_%s", MCapplicationstring, t_edition_name, MCModeGetEnvironment(), MC_BUILD_ENGINE_SHORT_VERSION);
307+
t_success = MCStringAppendFormat(*t_app_name, "%s%@_%@_%s", MCapplicationstring, *t_edition_name, MCModeGetEnvironment(), MC_BUILD_ENGINE_SHORT_VERSION);
323308

324309
if (t_success)
325310
{

engine/src/mode_development.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,27 +1086,11 @@ void MCModeSetRevLicenseLimits(MCExecContext& ctxt, MCArrayRef p_settings)
10861086
if (MCArrayFetchValue(p_settings, t_case_sensitive, MCNAME("class"), t_value))
10871087
{
10881088
MCAutoStringRef t_class;
1089-
if (ctxt . ConvertToString(t_value, &t_class))
1089+
if (!ctxt . ConvertToString(t_value, &t_class) ||
1090+
!MCStringToLicenseClass(*t_class, MClicenseparameters . license_class))
10901091
{
1091-
static struct { const char *tag; uint32_t value; } s_class_map[] =
1092-
{
1093-
{ "community", kMCLicenseClassCommunity },
1094-
{ "evaluation", kMCLicenseClassEvaluation },
1095-
{ "commercial", kMCLicenseClassCommercial },
1096-
{ "professional evaluation", kMCLicenseClassProfessionalEvaluation },
1097-
{ "professional", kMCLicenseClassProfessional },
1098-
{ "", kMCLicenseClassNone }
1099-
};
1100-
1101-
uint4 t_index;
1102-
for(t_index = 0; s_class_map[t_index] . tag != NULL; ++t_index)
1103-
if (MCStringIsEqualToCString(*t_class, s_class_map[t_index] . tag, kMCCompareCaseless))
1104-
break;
1105-
1106-
MClicenseparameters . license_class = s_class_map[t_index] . value;
1107-
}
1108-
else
11091092
MClicenseparameters . license_class = kMCLicenseClassNone;
1093+
}
11101094
}
11111095

11121096
if (MCArrayFetchValue(p_settings, t_case_sensitive, MCNAME("multiplicity"), t_value))
@@ -1309,16 +1293,6 @@ void MCModeGetRevCrashReportSettings(MCExecContext& ctxt, MCArrayRef& r_settings
13091293

13101294
void MCModeGetRevLicenseInfo(MCExecContext& ctxt, MCStringRef& r_info)
13111295
{
1312-
static const char *s_class_types[] =
1313-
{
1314-
"",
1315-
"Community",
1316-
"Evaluation",
1317-
"Commercial",
1318-
"Professional Evaluation",
1319-
"Professional",
1320-
};
1321-
13221296
static const char *s_deploy_targets[] =
13231297
{
13241298
"Windows",
@@ -1350,10 +1324,14 @@ void MCModeGetRevLicenseInfo(MCExecContext& ctxt, MCStringRef& r_info)
13501324
t_license_org = kMCEmptyString;
13511325

13521326

1327+
MCAutoStringRef t_license_class;
1328+
if (t_success)
1329+
t_success = MCStringFromLicenseClass(MClicenseparameters . license_class, false, &t_license_class);
1330+
13531331
if (t_success)
1354-
t_success = MCStringAppendFormat(*t_info, "%@\n%@\n%s\n%u\n",
1332+
t_success = MCStringAppendFormat(*t_info, "%@\n%@\n%@\n%u\n",
13551333
t_license_name, t_license_org,
1356-
s_class_types[MClicenseparameters . license_class],
1334+
*t_license_class,
13571335
MClicenseparameters . license_multiplicity);
13581336

13591337
if (MClicenseparameters . deploy_targets != 0)

0 commit comments

Comments
 (0)