Global Metrics
path: .metrics.nom.functions
old: 14.0
new: 13.0
path: .metrics.nom.total
old: 14.0
new: 13.0
path: .metrics.nargs.average
old: 2.2857142857142856
new: 2.0
path: .metrics.nargs.sum
old: 32.0
new: 26.0
path: .metrics.loc.cloc
old: 106.0
new: 96.0
path: .metrics.loc.blank
old: 83.0
new: 89.0
path: .metrics.loc.lloc
old: 201.0
new: 204.0
path: .metrics.loc.ploc
old: 474.0
new: 404.0
path: .metrics.loc.sloc
old: 663.0
new: 589.0
path: .metrics.cognitive.sum
old: 120.0
new: 91.0
path: .metrics.cognitive.average
old: 8.571428571428571
new: 7.0
path: .metrics.cyclomatic.sum
old: 91.0
new: 83.0
path: .metrics.cyclomatic.average
old: 5.6875
new: 5.928571428571429
path: .metrics.halstead.volume
old: 22122.126001357676
new: 16240.753283379898
path: .metrics.halstead.difficulty
old: 58.44387755102041
new: 54.004672897196265
path: .metrics.halstead.effort
old: 1292902.8231915927
new: 877076.5686729976
path: .metrics.halstead.n2
old: 294.0
new: 214.0
path: .metrics.halstead.estimated_program_length
old: 2551.5851182405904
new: 1778.885367761514
path: .metrics.halstead.time
old: 71827.93462175515
new: 48726.476037388755
path: .metrics.halstead.vocabulary
old: 323.0
new: 240.0
path: .metrics.halstead.bugs
old: 3.955997433179009
new: 3.054244153376359
path: .metrics.halstead.level
old: 0.0171104321257093
new: 0.01851691615471143
path: .metrics.halstead.N2
old: 1185.0
new: 889.0
path: .metrics.halstead.n1
old: 29.0
new: 26.0
path: .metrics.halstead.length
old: 2654.0
new: 2054.0
path: .metrics.halstead.purity_ratio
old: 0.9614111221705316
new: 0.8660590884914868
path: .metrics.halstead.N1
old: 1469.0
new: 1165.0
path: .metrics.mi.mi_sei
old: -47.79395401425897
new: -40.62594521009537
path: .metrics.mi.mi_original
old: -7.200289369624457
new: -1.835954959995192
path: .metrics.nexits.average
old: 1.0
new: 3.3846153846153846
path: .metrics.nexits.sum
old: 14.0
new: 44.0
Spaces Data
Minimal test - lines (353, 422)
path: .spaces[9].metrics.nargs.average
old: 3.0
new: 2.0
path: .spaces[9].metrics.nargs.sum
old: 3.0
new: 2.0
path: .spaces[9].metrics.cognitive.sum
old: 0.0
new: 10.0
path: .spaces[9].metrics.cognitive.average
old: 0.0
new: 10.0
path: .spaces[9].metrics.loc.cloc
old: 0.0
new: 8.0
path: .spaces[9].metrics.loc.sloc
old: 4.0
new: 70.0
path: .spaces[9].metrics.loc.blank
old: 0.0
new: 14.0
path: .spaces[9].metrics.loc.lloc
old: 1.0
new: 28.0
path: .spaces[9].metrics.loc.ploc
old: 4.0
new: 48.0
path: .spaces[9].metrics.halstead.bugs
old: 0.02502537766060993
new: 0.3327796801546092
path: .spaces[9].metrics.halstead.N1
old: 14.0
new: 146.0
path: .spaces[9].metrics.halstead.n1
old: 9.0
new: 20.0
path: .spaces[9].metrics.halstead.n2
old: 9.0
new: 54.0
path: .spaces[9].metrics.halstead.effort
old: 650.5083002250007
new: 31544.023097395067
path: .spaces[9].metrics.halstead.purity_ratio
old: 2.194563462536985
new: 1.563789318955018
path: .spaces[9].metrics.halstead.difficulty
old: 6.0
new: 20.0
path: .spaces[9].metrics.halstead.estimated_program_length
old: 57.05865002596162
new: 397.20248701457456
path: .spaces[9].metrics.halstead.level
old: 0.16666666666666666
new: 0.05
path: .spaces[9].metrics.halstead.volume
old: 108.41805003750012
new: 1577.2011548697533
path: .spaces[9].metrics.halstead.N2
old: 12.0
new: 108.0
path: .spaces[9].metrics.halstead.vocabulary
old: 18.0
new: 74.0
path: .spaces[9].metrics.halstead.time
old: 36.13935001250004
new: 1752.4457276330593
path: .spaces[9].metrics.halstead.length
old: 26.0
new: 254.0
path: .spaces[9].metrics.cyclomatic.sum
old: 1.0
new: 10.0
path: .spaces[9].metrics.cyclomatic.average
old: 1.0
new: 10.0
path: .spaces[9].metrics.nexits.sum
old: 1.0
new: 5.0
path: .spaces[9].metrics.nexits.average
old: 1.0
new: 5.0
path: .spaces[9].metrics.mi.mi_visual_studio
old: 72.48237397084954
new: 36.01442104140288
path: .spaces[9].metrics.mi.mi_original
old: 123.94485949015272
new: 61.58465998079893
path: .spaces[9].metrics.mi.mi_sei
old: 103.2156019975144
new: 39.170606286076286
Code
already_AddRefed nsOSHelperAppService::GetByExtension(
const nsString& aFileExt, const char* aTypeHint) {
if (aFileExt.IsEmpty()) return nullptr;
// Determine the mime type.
nsAutoCString typeToUse;
if (aTypeHint && *aTypeHint) {
typeToUse.Assign(aTypeHint);
} else if (!GetMIMETypeFromOSForExtension(NS_ConvertUTF16toUTF8(aFileExt),
typeToUse)) {
return nullptr;
}
RefPtr mimeInfo = new nsMIMEInfoWin(typeToUse);
// windows registry assumes your file extension is going to include the '.',
// but our APIs expect it to not be there, so make sure we normalize that bit.
nsAutoString fileExtToUse;
if (aFileExt.First() != char16_t('.')) fileExtToUse = char16_t('.');
fileExtToUse.Append(aFileExt);
// don't append the '.' for our APIs.
nsAutoCString lowerFileExt =
NS_ConvertUTF16toUTF8(Substring(fileExtToUse, 1));
ToLowerCase(lowerFileExt);
mimeInfo->AppendExtension(lowerFileExt);
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
nsAutoString appInfo;
bool found;
// Retrieve the default application for this extension
NS_ENSURE_TRUE(mAppAssoc, nullptr);
nsString assocType(fileExtToUse);
wchar_t* pResult = nullptr;
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(), AT_FILEEXTENSION,
AL_EFFECTIVE, &pResult);
if (SUCCEEDED(hr)) {
found = true;
appInfo.Assign(pResult);
CoTaskMemFree(pResult);
} else {
found = false;
}
// Bug 358297 - ignore the default handler, force the user to choose app
if (appInfo.EqualsLiteral("XPSViewer.Document")) found = false;
if (!found) {
return nullptr;
}
// Get other nsIMIMEInfo fields from registry, if possible.
nsAutoString defaultDescription;
nsCOMPtr defaultApplication;
if (NS_FAILED(GetDefaultAppInfo(appInfo, defaultDescription,
getter_AddRefs(defaultApplication)))) {
return nullptr;
}
mimeInfo->SetDefaultDescription(defaultDescription);
mimeInfo->SetDefaultApplicationHandler(defaultApplication);
// Grab the general description
GetMIMEInfoFromRegistry(appInfo, mimeInfo);
return mimeInfo.forget();
}
Minimal test - lines (71, 113)
path: .spaces[3].metrics.halstead.N2
old: 28.0
new: 62.0
path: .spaces[3].metrics.halstead.difficulty
old: 8.105263157894736
new: 14.243243243243244
path: .spaces[3].metrics.halstead.time
old: 148.03888060084412
new: 714.945400963218
path: .spaces[3].metrics.halstead.effort
old: 2664.699850815194
new: 12869.017217337923
path: .spaces[3].metrics.halstead.purity_ratio
old: 1.7726025456781849
new: 1.670297088086159
path: .spaces[3].metrics.halstead.estimated_program_length
old: 118.76437056043838
new: 262.23664282952694
path: .spaces[3].metrics.halstead.n2
old: 19.0
new: 37.0
path: .spaces[3].metrics.halstead.volume
old: 328.76166990577076
new: 903.5173378396644
path: .spaces[3].metrics.halstead.vocabulary
old: 30.0
new: 54.0
path: .spaces[3].metrics.halstead.level
old: 0.1233766233766234
new: 0.07020872865275142
path: .spaces[3].metrics.halstead.N1
old: 39.0
new: 95.0
path: .spaces[3].metrics.halstead.n1
old: 11.0
new: 17.0
path: .spaces[3].metrics.halstead.length
old: 67.0
new: 157.0
path: .spaces[3].metrics.halstead.bugs
old: 0.06406845881224356
new: 0.18305250085029412
path: .spaces[3].metrics.loc.cloc
old: 7.0
new: 4.0
path: .spaces[3].metrics.loc.ploc
old: 15.0
new: 35.0
path: .spaces[3].metrics.loc.lloc
old: 8.0
new: 16.0
path: .spaces[3].metrics.loc.sloc
old: 25.0
new: 43.0
path: .spaces[3].metrics.loc.blank
old: 3.0
new: 4.0
path: .spaces[3].metrics.cognitive.sum
old: 2.0
new: 16.0
path: .spaces[3].metrics.cognitive.average
old: 2.0
new: 16.0
path: .spaces[3].metrics.nexits.average
old: 1.0
new: 5.0
path: .spaces[3].metrics.nexits.sum
old: 1.0
new: 5.0
path: .spaces[3].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[3].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[3].metrics.mi.mi_visual_studio
old: 51.47864305124529
new: 42.5940482856294
path: .spaces[3].metrics.mi.mi_sei
old: 88.15182797777285
new: 52.94925578378689
path: .spaces[3].metrics.mi.mi_original
old: 88.02847961762946
new: 72.83582256842627
path: .spaces[3].metrics.cyclomatic.sum
old: 3.0
new: 8.0
path: .spaces[3].metrics.cyclomatic.average
old: 3.0
new: 8.0
Code
nsresult nsOSHelperAppService::OSProtocolHandlerExists(
const char* aProtocolScheme, bool* aHandlerExists) {
// look up the protocol scheme in the windows registry....if we find a match
// then we have a handler for it...
*aHandlerExists = false;
if (aProtocolScheme && *aProtocolScheme) {
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
wchar_t* pResult = nullptr;
NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
// We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(), AT_URLPROTOCOL,
AL_EFFECTIVE, &pResult);
if (SUCCEEDED(hr)) {
CoTaskMemFree(pResult);
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) {
return NS_ERROR_NOT_AVAILABLE;
}
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
nsDependentString(scheme.get()),
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) {
// Open will fail if the registry key path doesn't exist.
return NS_OK;
}
bool hasValue;
rv = regKey->HasValue(u"URL Protocol"_ns, &hasValue);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
if (!hasValue) {
return NS_OK;
}
*aHandlerExists = true;
}
}
return NS_OK;
}
Minimal test - lines (115, 148)
path: .spaces[4].metrics.nargs.average
old: 6.0
new: 2.0
path: .spaces[4].metrics.nargs.sum
old: 6.0
new: 2.0
path: .spaces[4].metrics.nexits.average
old: 1.0
new: 4.0
path: .spaces[4].metrics.nexits.sum
old: 1.0
new: 4.0
path: .spaces[4].metrics.halstead.purity_ratio
old: 1.1873369084411656
new: 1.8654612934877235
path: .spaces[4].metrics.halstead.n2
old: 35.0
new: 41.0
path: .spaces[4].metrics.halstead.level
old: 0.0368421052631579
new: 0.0730837789661319
path: .spaces[4].metrics.halstead.length
old: 224.0
new: 155.0
path: .spaces[4].metrics.halstead.N2
old: 95.0
new: 66.0
path: .spaces[4].metrics.halstead.estimated_program_length
old: 265.9634674908211
new: 289.1465004905972
path: .spaces[4].metrics.halstead.bugs
old: 0.3576853279557205
new: 0.1788070010828995
path: .spaces[4].metrics.halstead.n1
old: 20.0
new: 17.0
path: .spaces[4].metrics.halstead.volume
old: 1295.024575829524
new: 907.9870542447736
path: .spaces[4].metrics.halstead.effort
old: 35150.667058229934
new: 12423.920425154098
path: .spaces[4].metrics.halstead.difficulty
old: 27.142857142857142
new: 13.682926829268292
path: .spaces[4].metrics.halstead.vocabulary
old: 55.0
new: 58.0
path: .spaces[4].metrics.halstead.N1
old: 129.0
new: 89.0
path: .spaces[4].metrics.halstead.time
old: 1952.8148365683296
new: 690.2178013974499
path: .spaces[4].metrics.loc.lloc
old: 23.0
new: 12.0
path: .spaces[4].metrics.loc.blank
old: 3.0
new: 2.0
path: .spaces[4].metrics.loc.ploc
old: 48.0
new: 30.0
path: .spaces[4].metrics.loc.sloc
old: 67.0
new: 34.0
path: .spaces[4].metrics.loc.cloc
old: 16.0
new: 2.0
path: .spaces[4].metrics.cyclomatic.sum
old: 12.0
new: 6.0
path: .spaces[4].metrics.cyclomatic.average
old: 12.0
new: 6.0
path: .spaces[4].metrics.cognitive.average
old: 24.0
new: 7.0
path: .spaces[4].metrics.cognitive.sum
old: 24.0
new: 7.0
path: .spaces[4].metrics.mi.mi_visual_studio
old: 36.75982328563755
new: 45.072843784623565
path: .spaces[4].metrics.mi.mi_original
old: 62.85929781844021
new: 77.07456287170629
path: .spaces[4].metrics.mi.mi_sei
old: 50.54702382273719
new: 54.45295467390781
Code
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(
const nsACString& aScheme, nsAString& _retval) {
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) return NS_ERROR_NOT_AVAILABLE;
NS_ConvertASCIItoUTF16 buf(aScheme);
if (mozilla::IsWin8OrLater()) {
wchar_t result[1024];
DWORD resultSize = 1024;
HRESULT hr = AssocQueryString(0x1000 /* ASSOCF_IS_PROTOCOL */,
ASSOCSTR_FRIENDLYAPPNAME, buf.get(), NULL,
result, &resultSize);
if (SUCCEEDED(hr)) {
_retval = result;
return NS_OK;
}
}
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
wchar_t* pResult = nullptr;
// We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(), AT_URLPROTOCOL,
AL_EFFECTIVE, &pResult);
if (SUCCEEDED(hr)) {
nsCOMPtr app;
nsAutoString appInfo(pResult);
CoTaskMemFree(pResult);
if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
return NS_OK;
}
return NS_ERROR_NOT_AVAILABLE;
}
Minimal test - lines (532, 557)
path: .spaces[11].metrics.nexits.sum
old: 0.0
new: 3.0
path: .spaces[11].metrics.nexits.average
old: 0.0
new: 3.0
path: .spaces[11].metrics.nargs.average
old: 4.0
new: 3.0
path: .spaces[11].metrics.nargs.sum
old: 4.0
new: 3.0
path: .spaces[11].metrics.mi.mi_visual_studio
old: 54.74255727954002
new: 49.622054918054715
path: .spaces[11].metrics.mi.mi_sei
old: 59.55314293763702
new: 67.85113200640815
path: .spaces[11].metrics.mi.mi_original
old: 93.60977294801344
new: 84.85371390987356
path: .spaces[11].metrics.cyclomatic.sum
old: 2.0
new: 3.0
path: .spaces[11].metrics.cyclomatic.average
old: 1.0
new: 3.0
path: .spaces[11].metrics.halstead.N1
old: 34.0
new: 58.0
path: .spaces[11].metrics.halstead.vocabulary
old: 28.0
new: 41.0
path: .spaces[11].metrics.halstead.effort
old: 2222.9209159594357
new: 6490.880313287294
path: .spaces[11].metrics.halstead.bugs
old: 0.05677555915985361
new: 0.1159883791090294
path: .spaces[11].metrics.halstead.length
old: 68.0
new: 100.0
path: .spaces[11].metrics.halstead.volume
old: 326.90013469991703
new: 535.7552004618084
path: .spaces[11].metrics.halstead.level
old: 0.14705882352941177
new: 0.08253968253968254
path: .spaces[11].metrics.halstead.N2
old: 34.0
new: 42.0
path: .spaces[11].metrics.halstead.n1
old: 8.0
new: 15.0
path: .spaces[11].metrics.halstead.purity_ratio
old: 1.6240964984962831
new: 1.808147916057962
path: .spaces[11].metrics.halstead.difficulty
old: 6.8
new: 12.115384615384617
path: .spaces[11].metrics.halstead.time
old: 123.49560644219088
new: 360.60446184929407
path: .spaces[11].metrics.halstead.estimated_program_length
old: 110.43856189774723
new: 180.8147916057962
path: .spaces[11].metrics.halstead.n2
old: 20.0
new: 26.0
path: .spaces[11].metrics.cognitive.sum
old: 0.0
new: 2.0
path: .spaces[11].metrics.cognitive.average
old: 0.0
new: 2.0
path: .spaces[11].metrics.loc.sloc
old: 18.0
new: 26.0
path: .spaces[11].metrics.loc.ploc
old: 16.0
new: 19.0
path: .spaces[11].metrics.loc.cloc
old: 0.0
new: 2.0
path: .spaces[11].metrics.loc.blank
old: 2.0
new: 5.0
path: .spaces[11].metrics.loc.lloc
old: 1.0
new: 10.0
Code
nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString& aScheme,
bool* found,
nsIHandlerInfo** _retval) {
NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");
nsresult rv =
OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(), found);
if (NS_FAILED(rv)) return rv;
nsMIMEInfoWin* handlerInfo =
new nsMIMEInfoWin(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*_retval = handlerInfo);
if (!*found) {
// Code that calls this requires an object regardless if the OS has
// something for us, so we return the empty object.
return NS_OK;
}
nsAutoString desc;
GetApplicationDescription(aScheme, desc);
handlerInfo->SetDefaultDescription(desc);
return NS_OK;
}
Minimal test - lines (33, 39)
path: .spaces[0].metrics.halstead.estimated_program_length
old: 48.0
new: 57.05865002596162
path: .spaces[0].metrics.halstead.vocabulary
old: 16.0
new: 18.0
path: .spaces[0].metrics.halstead.n1
old: 8.0
new: 9.0
path: .spaces[0].metrics.halstead.length
old: 25.0
new: 32.0
path: .spaces[0].metrics.halstead.time
old: 30.555555555555557
new: 44.47920001538466
path: .spaces[0].metrics.halstead.volume
old: 100.0
new: 133.437600046154
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.92
new: 1.7830828133113006
path: .spaces[0].metrics.halstead.N1
old: 14.0
new: 20.0
path: .spaces[0].metrics.halstead.difficulty
old: 5.5
new: 6.0
path: .spaces[0].metrics.halstead.n2
old: 8.0
new: 9.0
path: .spaces[0].metrics.halstead.N2
old: 11.0
new: 12.0
path: .spaces[0].metrics.halstead.level
old: 0.18181818181818185
new: 0.16666666666666666
path: .spaces[0].metrics.halstead.bugs
old: 0.022376244815288552
new: 0.028740769637474364
path: .spaces[0].metrics.halstead.effort
old: 550.0
new: 800.6256002769239
path: .spaces[0].metrics.mi.mi_visual_studio
old: 72.72815577936825
new: 66.54933276535203
path: .spaces[0].metrics.mi.mi_original
old: 124.3651463827197
new: 113.79935902875198
path: .spaces[0].metrics.mi.mi_sei
old: 103.82194781317143
new: 88.57873879451489
path: .spaces[0].metrics.loc.lloc
old: 1.0
new: 2.0
path: .spaces[0].metrics.loc.ploc
old: 4.0
new: 7.0
path: .spaces[0].metrics.loc.sloc
old: 4.0
new: 7.0
path: .spaces[0].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[0].metrics.nexits.sum
old: 1.0
new: 0.0
Code
nsOSHelperAppService::nsOSHelperAppService()
: nsExternalHelperAppService(), mAppAssoc(nullptr) {
CoInitialize(nullptr);
CoCreateInstance(CLSID_ApplicationAssociationRegistration, nullptr,
CLSCTX_INPROC, IID_IApplicationAssociationRegistration,
(void**)&mAppAssoc);
}
Minimal test - lines (150, 186)
path: .spaces[5].metrics.cognitive.average
old: 2.0
new: 3.0
path: .spaces[5].metrics.cognitive.sum
old: 2.0
new: 3.0
path: .spaces[5].metrics.loc.blank
old: 1.0
new: 4.0
path: .spaces[5].metrics.loc.lloc
old: 4.0
new: 13.0
path: .spaces[5].metrics.loc.ploc
old: 9.0
new: 29.0
path: .spaces[5].metrics.loc.sloc
old: 14.0
new: 37.0
path: .spaces[5].metrics.cyclomatic.average
old: 2.0
new: 4.0
path: .spaces[5].metrics.cyclomatic.sum
old: 2.0
new: 4.0
path: .spaces[5].metrics.halstead.estimated_program_length
old: 66.43856189774725
new: 251.35313346239897
path: .spaces[5].metrics.halstead.length
old: 44.0
new: 147.0
path: .spaces[5].metrics.halstead.time
old: 95.08241808752196
new: 613.3750169688979
path: .spaces[5].metrics.halstead.bugs
old: 0.04769365003766825
new: 0.16527651140705427
path: .spaces[5].metrics.halstead.level
old: 0.1111111111111111
new: 0.0758974358974359
path: .spaces[5].metrics.halstead.effort
old: 1711.4835255753956
new: 11040.750305440162
path: .spaces[5].metrics.halstead.volume
old: 190.16483617504392
new: 837.9646385667405
path: .spaces[5].metrics.halstead.vocabulary
old: 20.0
new: 52.0
path: .spaces[5].metrics.halstead.difficulty
old: 9.0
new: 13.175675675675675
path: .spaces[5].metrics.halstead.n1
old: 10.0
new: 15.0
path: .spaces[5].metrics.halstead.N2
old: 18.0
new: 65.0
path: .spaces[5].metrics.halstead.purity_ratio
old: 1.509967315857892
new: 1.7098852616489724
path: .spaces[5].metrics.halstead.N1
old: 26.0
new: 82.0
path: .spaces[5].metrics.halstead.n2
old: 10.0
new: 37.0
path: .spaces[5].metrics.mi.mi_sei
old: 106.3227630645121
new: 59.57241588374017
path: .spaces[5].metrics.mi.mi_original
old: 100.49823673493546
new: 76.58205512384131
path: .spaces[5].metrics.mi.mi_visual_studio
old: 58.77089867540085
new: 44.78482755780193
path: .spaces[5].metrics.nexits.sum
old: 0.0
new: 4.0
path: .spaces[5].metrics.nexits.average
old: 0.0
new: 4.0
Code
NS_IMETHODIMP nsOSHelperAppService::IsCurrentAppOSDefaultForProtocol(
const nsACString& aScheme, bool* _retval) {
*_retval = false;
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
NS_ConvertASCIItoUTF16 buf(aScheme);
// Find the progID
wchar_t* pResult = nullptr;
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(), AT_URLPROTOCOL,
AL_EFFECTIVE, &pResult);
if (FAILED(hr)) {
return NS_ERROR_FAILURE;
}
nsAutoString progID(pResult);
// We are responsible for freeing returned strings.
CoTaskMemFree(pResult);
// Find the default executable.
nsAutoString description;
nsCOMPtr appFile;
nsresult rv = GetDefaultAppInfo(progID, description, getter_AddRefs(appFile));
if (NS_FAILED(rv)) {
return rv;
}
// Determine if the default executable is our executable.
nsCOMPtr ourBinary;
XRE_GetBinaryPath(getter_AddRefs(ourBinary));
bool isSame = false;
rv = appFile->Equals(ourBinary, &isSame);
if (NS_FAILED(rv)) {
return rv;
}
*_retval = isSame;
return NS_OK;
}
Minimal test - lines (50, 69)
path: .spaces[2].metrics.loc.lloc
old: 3.0
new: 7.0
path: .spaces[2].metrics.loc.blank
old: 0.0
new: 5.0
path: .spaces[2].metrics.loc.sloc
old: 7.0
new: 20.0
path: .spaces[2].metrics.loc.ploc
old: 7.0
new: 15.0
path: .spaces[2].metrics.halstead.difficulty
old: 8.863636363636363
new: 9.692307692307692
path: .spaces[2].metrics.halstead.bugs
old: 0.04608404073955524
new: 0.08214548871116752
path: .spaces[2].metrics.halstead.N2
old: 15.0
new: 36.0
path: .spaces[2].metrics.halstead.purity_ratio
old: 2.1539866035211115
new: 2.340192021072998
path: .spaces[2].metrics.halstead.estimated_program_length
old: 86.15946414084446
new: 175.51440158047484
path: .spaces[2].metrics.halstead.effort
old: 1625.577613892046
new: 3868.6323458988904
path: .spaces[2].metrics.halstead.N1
old: 25.0
new: 39.0
path: .spaces[2].metrics.halstead.length
old: 40.0
new: 75.0
path: .spaces[2].metrics.halstead.n2
old: 11.0
new: 26.0
path: .spaces[2].metrics.halstead.vocabulary
old: 24.0
new: 40.0
path: .spaces[2].metrics.halstead.n1
old: 13.0
new: 14.0
path: .spaces[2].metrics.halstead.volume
old: 183.39850002884623
new: 399.1446071165522
path: .spaces[2].metrics.halstead.level
old: 0.11282051282051282
new: 0.10317460317460318
path: .spaces[2].metrics.halstead.time
old: 90.309867438447
new: 214.92401921660505
path: .spaces[2].metrics.cognitive.average
old: 3.0
new: 2.0
path: .spaces[2].metrics.cognitive.sum
old: 3.0
new: 2.0
path: .spaces[2].metrics.cyclomatic.sum
old: 5.0
new: 3.0
path: .spaces[2].metrics.cyclomatic.average
old: 5.0
new: 3.0
path: .spaces[2].metrics.mi.mi_visual_studio
old: 65.04422011904839
new: 53.00272136725324
path: .spaces[2].metrics.mi.mi_sei
old: 85.27289251026212
new: 55.36277277816697
path: .spaces[2].metrics.mi.mi_original
old: 111.22561640357276
new: 90.63465353800304
path: .spaces[2].metrics.nargs.average
old: 1.0
new: 2.0
path: .spaces[2].metrics.nargs.sum
old: 1.0
new: 2.0
Code
static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
nsString& aFileExtension) {
nsAutoString mimeDatabaseKey;
mimeDatabaseKey.AssignLiteral("MIME\\Database\\Content Type\\");
AppendASCIItoUTF16(aMimeType, mimeDatabaseKey);
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) return NS_ERROR_NOT_AVAILABLE;
nsresult rv =
regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, mimeDatabaseKey,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_SUCCEEDED(rv))
regKey->ReadStringValue(u"Extension"_ns, aFileExtension);
return NS_OK;
}
Minimal test - lines (41, 45)
path: .spaces[1].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[1].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[1].metrics.loc.lloc
old: 1.0
new: 4.0
path: .spaces[1].metrics.loc.cloc
old: 1.0
new: 0.0
path: .spaces[1].metrics.loc.ploc
old: 3.0
new: 5.0
path: .spaces[1].metrics.loc.sloc
old: 4.0
new: 5.0
path: .spaces[1].metrics.halstead.time
old: 3.3333333333333335
new: 23.02495824621124
path: .spaces[1].metrics.halstead.n1
old: 5.0
new: 8.0
path: .spaces[1].metrics.halstead.N2
old: 3.0
new: 7.0
path: .spaces[1].metrics.halstead.bugs
old: 0.005108729549290353
new: 0.018529327165393225
path: .spaces[1].metrics.halstead.difficulty
old: 2.5
new: 5.6
path: .spaces[1].metrics.halstead.level
old: 0.4
new: 0.17857142857142858
path: .spaces[1].metrics.halstead.n2
old: 3.0
new: 5.0
path: .spaces[1].metrics.halstead.purity_ratio
old: 2.045565997075035
new: 1.7804820237218404
path: .spaces[1].metrics.halstead.effort
old: 60.0
new: 414.4492484318023
path: .spaces[1].metrics.halstead.vocabulary
old: 8.0
new: 13.0
path: .spaces[1].metrics.halstead.length
old: 8.0
new: 20.0
path: .spaces[1].metrics.halstead.volume
old: 24.0
new: 74.00879436282185
path: .spaces[1].metrics.halstead.N1
old: 5.0
new: 13.0
path: .spaces[1].metrics.halstead.estimated_program_length
old: 16.36452797660028
new: 35.60964047443681
path: .spaces[1].metrics.mi.mi_sei
old: 149.49958851942245
new: 100.63471585459688
path: .spaces[1].metrics.mi.mi_original
old: 131.78615143204846
new: 122.08534938837198
path: .spaces[1].metrics.mi.mi_visual_studio
old: 77.06792481406343
new: 71.39494116279063
path: .spaces[1].metrics.cyclomatic.sum
old: 1.0
new: 2.0
path: .spaces[1].metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .spaces[1].metrics.cognitive.average
old: 0.0
new: 1.0
path: .spaces[1].metrics.cognitive.sum
old: 0.0
new: 1.0
Code
nsOSHelperAppService::~nsOSHelperAppService() {
if (mAppAssoc) mAppAssoc->Release();
mAppAssoc = nullptr;
CoUninitialize();
}
Minimal test - lines (226, 249)
path: .spaces[7].metrics.loc.blank
old: 0.0
new: 5.0
path: .spaces[7].metrics.loc.sloc
old: 4.0
new: 24.0
path: .spaces[7].metrics.loc.ploc
old: 4.0
new: 19.0
path: .spaces[7].metrics.loc.lloc
old: 1.0
new: 13.0
path: .spaces[7].metrics.cognitive.sum
old: 0.0
new: 5.0
path: .spaces[7].metrics.cognitive.average
old: 0.0
new: 5.0
path: .spaces[7].metrics.cyclomatic.sum
old: 1.0
new: 6.0
path: .spaces[7].metrics.cyclomatic.average
old: 1.0
new: 6.0
path: .spaces[7].metrics.nexits.sum
old: 1.0
new: 4.0
path: .spaces[7].metrics.nexits.average
old: 1.0
new: 4.0
path: .spaces[7].metrics.mi.mi_original
old: 124.68625431117268
new: 84.62235371944678
path: .spaces[7].metrics.mi.mi_sei
old: 104.2852086291407
new: 46.994317223811606
path: .spaces[7].metrics.mi.mi_visual_studio
old: 72.91593819366824
new: 49.48675656107999
path: .spaces[7].metrics.halstead.estimated_program_length
old: 52.529325012980806
new: 191.69830097292416
path: .spaces[7].metrics.halstead.time
old: 25.53402713176138
new: 537.3161565435996
path: .spaces[7].metrics.halstead.N1
old: 12.0
new: 69.0
path: .spaces[7].metrics.halstead.difficulty
old: 4.888888888888889
new: 15.365384615384617
path: .spaces[7].metrics.halstead.vocabulary
old: 17.0
new: 43.0
path: .spaces[7].metrics.halstead.length
old: 23.0
new: 116.0
path: .spaces[7].metrics.halstead.n2
old: 9.0
new: 26.0
path: .spaces[7].metrics.halstead.n1
old: 8.0
new: 17.0
path: .spaces[7].metrics.halstead.bugs
old: 0.019852107840031902
new: 0.1513144307602043
path: .spaces[7].metrics.halstead.volume
old: 94.0116453487578
new: 629.4467115454433
path: .spaces[7].metrics.halstead.effort
old: 459.6124883717048
new: 9671.690817784793
path: .spaces[7].metrics.halstead.level
old: 0.20454545454545453
new: 0.06508135168961202
path: .spaces[7].metrics.halstead.purity_ratio
old: 2.2838836962165567
new: 1.6525715601114153
path: .spaces[7].metrics.halstead.N2
old: 11.0
new: 47.0
Code
bool nsOSHelperAppService::typeFromExtEquals(const char16_t* aExt,
const char* aType) {
if (!aType) return false;
nsAutoString fileExtToUse;
if (aExt[0] != char16_t('.')) fileExtToUse = char16_t('.');
fileExtToUse.Append(aExt);
bool eq = false;
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) return eq;
nsresult rv =
regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, fileExtToUse,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) return eq;
nsAutoString type;
rv = regKey->ReadStringValue(u"Content Type"_ns, type);
if (NS_SUCCEEDED(rv)) eq = type.LowerCaseEqualsASCII(aType);
return eq;
}
Minimal test - lines (425, 529)
path: .spaces[10].metrics.cognitive.sum
old: 83.0
new: 18.0
path: .spaces[10].metrics.cognitive.average
old: 83.0
new: 18.0
path: .spaces[10].metrics.mi.mi_original
old: 12.170225571999111
new: 51.26615981725078
path: .spaces[10].metrics.mi.mi_sei
old: -23.801983951970424
new: 33.150596617382675
path: .spaces[10].metrics.mi.mi_visual_studio
old: 7.117090977777258
new: 29.9802104194449
path: .spaces[10].metrics.nexits.sum
old: 2.0
new: 4.0
path: .spaces[10].metrics.nexits.average
old: 2.0
new: 4.0
path: .spaces[10].metrics.halstead.N2
old: 800.0
new: 161.0
path: .spaces[10].metrics.halstead.n2
old: 167.0
new: 47.0
path: .spaces[10].metrics.halstead.n1
old: 26.0
new: 21.0
path: .spaces[10].metrics.halstead.N1
old: 979.0
new: 230.0
path: .spaces[10].metrics.halstead.bugs
old: 2.970267191293152
new: 0.6474889241081817
path: .spaces[10].metrics.halstead.estimated_program_length
old: 1355.2900495148351
new: 353.3043419072029
path: .spaces[10].metrics.halstead.difficulty
old: 62.2754491017964
new: 35.96808510638298
path: .spaces[10].metrics.halstead.time
old: 46730.73956111747
new: 4756.175732689451
path: .spaces[10].metrics.halstead.vocabulary
old: 193.0
new: 68.0
path: .spaces[10].metrics.halstead.effort
old: 841153.3121001145
new: 85611.16318841012
path: .spaces[10].metrics.halstead.purity_ratio
old: 0.7618268968605032
new: 0.9035916672818488
path: .spaces[10].metrics.halstead.volume
old: 13506.981069299916
new: 2380.1979709288826
path: .spaces[10].metrics.halstead.length
old: 1779.0
new: 391.0
path: .spaces[10].metrics.halstead.level
old: 0.016057692307692308
new: 0.027802425317953267
path: .spaces[10].metrics.cyclomatic.average
old: 53.0
new: 17.0
path: .spaces[10].metrics.cyclomatic.sum
old: 53.0
new: 17.0
path: .spaces[10].metrics.loc.blank
old: 46.0
new: 10.0
path: .spaces[10].metrics.loc.lloc
old: 136.0
new: 38.0
path: .spaces[10].metrics.loc.ploc
old: 293.0
new: 72.0
path: .spaces[10].metrics.loc.sloc
old: 403.0
new: 105.0
path: .spaces[10].metrics.loc.cloc
old: 64.0
new: 23.0
Code
nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
const nsACString& aFileExt,
bool* aFound, nsIMIMEInfo** aMIMEInfo) {
*aFound = false;
const nsCString& flatType = PromiseFlatCString(aMIMEType);
nsAutoString fileExtension;
CopyUTF8toUTF16(aFileExt, fileExtension);
/* XXX The octet-stream check is a gross hack to wallpaper over the most
* common Win32 extension issues caused by the fix for bug 116938. See bug
* 120327, comment 271 for why this is needed. Not even sure we
* want to remove this once we have fixed all this stuff to work
* right; any info we get from the OS on this type is pretty much
* useless....
*/
bool haveMeaningfulMimeType =
!aMIMEType.IsEmpty() &&
!aMIMEType.LowerCaseEqualsLiteral(APPLICATION_OCTET_STREAM);
LOG(("Extension lookup on '%s' with mimetype '%s'%s\n", fileExtension.get(),
flatType.get(),
haveMeaningfulMimeType ? " (treated as meaningful)" : ""));
RefPtr mi;
// We should have *something* to go on here.
nsAutoString extensionFromMimeType;
if (haveMeaningfulMimeType) {
GetExtensionFromWindowsMimeDatabase(aMIMEType, extensionFromMimeType);
}
if (fileExtension.IsEmpty() && extensionFromMimeType.IsEmpty()) {
// Without an extension from the mimetype or the file, we can't
// do anything here.
mi = new nsMIMEInfoWin(flatType.get());
mi.forget(aMIMEInfo);
return NS_OK;
}
// Either fileExtension or extensionFromMimeType must now be non-empty.
*aFound = true;
// On Windows, we prefer the file extension for lookups over the mimetype,
// because that's how windows does things.
// If we have no file extension or it doesn't match the mimetype, use the
// mime type's default file extension instead.
bool usedMimeTypeExtensionForLookup = false;
if (fileExtension.IsEmpty() ||
(!extensionFromMimeType.IsEmpty() &&
!typeFromExtEquals(fileExtension.get(), flatType.get()))) {
usedMimeTypeExtensionForLookup = true;
fileExtension = extensionFromMimeType;
LOG(("Now using '%s' mimetype's default file extension '%s' for lookup\n",
flatType.get(), fileExtension.get()));
}
// If we have an extension, use it for lookup:
mi = GetByExtension(fileExtension, flatType.get());
LOG(("Extension lookup on '%s' found: 0x%p\n", fileExtension.get(),
mi.get()));
if (mi) {
bool hasDefault = false;
mi->GetHasDefaultHandler(&hasDefault);
// If we don't find a default handler description, see if we can find one
// using the mimetype.
if (!hasDefault && !usedMimeTypeExtensionForLookup) {
RefPtr miFromMimeType =
GetByExtension(extensionFromMimeType, flatType.get());
LOG(("Mime-based ext. lookup for '%s' found 0x%p\n",
extensionFromMimeType.get(), miFromMimeType.get()));
if (miFromMimeType) {
nsAutoString desc;
miFromMimeType->GetDefaultDescription(desc);
mi->SetDefaultDescription(desc);
}
}
mi.forget(aMIMEInfo);
return NS_OK;
}
// The extension didn't work. Try the extension from the mimetype if
// different:
if (!extensionFromMimeType.IsEmpty() && !usedMimeTypeExtensionForLookup) {
mi = GetByExtension(extensionFromMimeType, flatType.get());
LOG(("Mime-based ext. lookup for '%s' found 0x%p\n",
extensionFromMimeType.get(), mi.get()));
}
if (mi) {
mi.forget(aMIMEInfo);
return NS_OK;
}
// This didn't work either, so just return an empty dummy mimeinfo.
*aFound = false;
mi = new nsMIMEInfoWin(flatType.get());
// If we didn't resort to the mime type's extension, we must have had a
// valid extension, so stick its lowercase version on the mime info.
if (!usedMimeTypeExtensionForLookup) {
nsAutoCString lowerFileExt;
ToLowerCase(aFileExt, lowerFileExt);
mi->AppendExtension(lowerFileExt);
}
mi.forget(aMIMEInfo);
return NS_OK;
}
Minimal test - lines (559, 589)
path: .spaces[12].metrics.loc.blank
old: 3.0
new: 5.0
path: .spaces[12].metrics.loc.lloc
old: 10.0
new: 14.0
path: .spaces[12].metrics.loc.ploc
old: 24.0
new: 22.0
path: .spaces[12].metrics.loc.sloc
old: 29.0
new: 31.0
path: .spaces[12].metrics.loc.cloc
old: 2.0
new: 4.0
path: .spaces[12].metrics.nexits.average
old: 0.0
new: 5.0
path: .spaces[12].metrics.nexits.sum
old: 0.0
new: 5.0
path: .spaces[12].metrics.cognitive.average
old: 2.0
new: 6.0
path: .spaces[12].metrics.cognitive.sum
old: 2.0
new: 6.0
path: .spaces[12].metrics.halstead.effort
old: 20384.915451104112
new: 10003.018139743335
path: .spaces[12].metrics.halstead.purity_ratio
old: 1.6438369355142703
new: 1.7007733843239057
path: .spaces[12].metrics.halstead.bugs
old: 0.24874327896216705
new: 0.15475075725185247
path: .spaces[12].metrics.halstead.N1
old: 109.0
new: 70.0
path: .spaces[12].metrics.halstead.level
old: 0.0574712643678161
new: 0.06588235294117648
path: .spaces[12].metrics.halstead.n1
old: 18.0
new: 17.0
path: .spaces[12].metrics.halstead.n2
old: 45.0
new: 28.0
path: .spaces[12].metrics.halstead.volume
old: 1171.5468650059836
new: 659.022371559561
path: .spaces[12].metrics.halstead.vocabulary
old: 63.0
new: 45.0
path: .spaces[12].metrics.halstead.N2
old: 87.0
new: 50.0
path: .spaces[12].metrics.halstead.estimated_program_length
old: 322.19203936079697
new: 204.09280611886868
path: .spaces[12].metrics.halstead.time
old: 1132.4953028391174
new: 555.7232299857409
path: .spaces[12].metrics.halstead.difficulty
old: 17.4
new: 15.178571428571429
path: .spaces[12].metrics.halstead.length
old: 196.0
new: 120.0
path: .spaces[12].metrics.cyclomatic.average
old: 2.0
new: 7.0
path: .spaces[12].metrics.cyclomatic.sum
old: 2.0
new: 7.0
path: .spaces[12].metrics.mi.mi_sei
old: 58.61624822586581
new: 66.84857704733507
path: .spaces[12].metrics.mi.mi_visual_studio
old: 46.34280128352675
new: 46.787993206248274
path: .spaces[12].metrics.mi.mi_original
old: 79.24619019483075
new: 80.00746838268455
Code
bool nsOSHelperAppService::GetMIMETypeFromOSForExtension(
const nsACString& aExtension, nsACString& aMIMEType) {
if (aExtension.IsEmpty()) return false;
// windows registry assumes your file extension is going to include the '.'.
// so make sure it's there...
nsAutoString fileExtToUse;
if (aExtension.First() != '.') fileExtToUse = char16_t('.');
AppendUTF8toUTF16(aExtension, fileExtToUse);
// Try to get an entry from the windows registry.
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) return false;
nsresult rv =
regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, fileExtToUse,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) return false;
nsAutoString mimeType;
if (NS_FAILED(regKey->ReadStringValue(u"Content Type"_ns, mimeType)) ||
mimeType.IsEmpty()) {
return false;
}
// Content-Type is always in ASCII
aMIMEType.Truncate();
LossyAppendUTF16toASCII(mimeType, aMIMEType);
return true;
}
Minimal test - lines (255, 351)
path: .spaces[8].metrics.nargs.sum
old: 1.0
new: 3.0
path: .spaces[8].metrics.nargs.average
old: 1.0
new: 3.0
path: .spaces[8].metrics.mi.mi_sei
old: 87.75489591736567
new: 33.55726683603002
path: .spaces[8].metrics.mi.mi_original
old: 113.1577385127604
new: 54.02145364747271
path: .spaces[8].metrics.mi.mi_visual_studio
old: 66.17411608933357
new: 31.59149336109515
path: .spaces[8].metrics.halstead.N2
old: 15.0
new: 170.0
path: .spaces[8].metrics.halstead.N1
old: 19.0
new: 201.0
path: .spaces[8].metrics.halstead.volume
old: 144.4295354570819
new: 2338.7026575737054
path: .spaces[8].metrics.halstead.difficulty
old: 10.3125
new: 30.775862068965516
path: .spaces[8].metrics.halstead.n1
old: 11.0
new: 21.0
path: .spaces[8].metrics.halstead.length
old: 34.0
new: 371.0
path: .spaces[8].metrics.halstead.effort
old: 1489.4295844011572
new: 71975.59040981146
path: .spaces[8].metrics.halstead.n2
old: 8.0
new: 58.0
path: .spaces[8].metrics.halstead.time
old: 82.74608802228651
new: 3998.643911656192
path: .spaces[8].metrics.halstead.purity_ratio
old: 1.8251102295591255
new: 1.164424699719011
path: .spaces[8].metrics.halstead.estimated_program_length
old: 62.05374780501027
new: 432.0015635957531
path: .spaces[8].metrics.halstead.level
old: 0.09696969696969696
new: 0.032492997198879554
path: .spaces[8].metrics.halstead.bugs
old: 0.043473579057860645
new: 0.5767694328990486
path: .spaces[8].metrics.halstead.vocabulary
old: 19.0
new: 79.0
path: .spaces[8].metrics.loc.lloc
old: 4.0
new: 37.0
path: .spaces[8].metrics.loc.cloc
old: 0.0
new: 17.0
path: .spaces[8].metrics.loc.ploc
old: 6.0
new: 67.0
path: .spaces[8].metrics.loc.blank
old: 1.0
new: 13.0
path: .spaces[8].metrics.loc.sloc
old: 7.0
new: 97.0
path: .spaces[8].metrics.cyclomatic.average
old: 2.0
new: 11.0
path: .spaces[8].metrics.cyclomatic.sum
old: 2.0
new: 11.0
path: .spaces[8].metrics.nexits.sum
old: 2.0
new: 5.0
path: .spaces[8].metrics.nexits.average
old: 2.0
new: 5.0
path: .spaces[8].metrics.cognitive.average
old: 1.0
new: 18.0
path: .spaces[8].metrics.cognitive.sum
old: 1.0
new: 18.0
Code
nsresult nsOSHelperAppService::GetDefaultAppInfo(
const nsAString& aAppInfo, nsAString& aDefaultDescription,
nsIFile** aDefaultApplication) {
nsAutoString handlerCommand;
// If all else fails, use the file type key name, which will be
// something like "pngfile" for .pngs, "WMVFile" for .wmvs, etc.
aDefaultDescription = aAppInfo;
*aDefaultApplication = nullptr;
if (aAppInfo.IsEmpty()) return NS_ERROR_FAILURE;
// aAppInfo may be a file, file path, program id, or
// Applications reference -
// c:\dir\app.exe
// Applications\appfile.exe/dll (shell\open...)
// ProgID.progid (shell\open...)
nsAutoString handlerKeyName(aAppInfo);
nsCOMPtr chkKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!chkKey) return NS_ERROR_FAILURE;
nsresult rv =
chkKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, handlerKeyName,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) {
// It's a file system path to a handler
handlerCommand.Assign(aAppInfo);
} else {
handlerKeyName.AppendLiteral("\\shell\\open\\command");
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) return NS_ERROR_FAILURE;
nsresult rv =
regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, handlerKeyName,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// OK, the default value here is the description of the type.
rv = regKey->ReadStringValue(u""_ns, handlerCommand);
if (NS_FAILED(rv)) {
// Check if there is a DelegateExecute string
nsAutoString delegateExecute;
rv = regKey->ReadStringValue(u"DelegateExecute"_ns, delegateExecute);
NS_ENSURE_SUCCESS(rv, rv);
// Look for InProcServer32
nsAutoString delegateExecuteRegPath;
delegateExecuteRegPath.AssignLiteral("CLSID\\");
delegateExecuteRegPath.Append(delegateExecute);
delegateExecuteRegPath.AppendLiteral("\\InProcServer32");
rv = chkKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
delegateExecuteRegPath,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_SUCCEEDED(rv)) {
rv = chkKey->ReadStringValue(u""_ns, handlerCommand);
}
if (NS_FAILED(rv)) {
// Look for LocalServer32
delegateExecuteRegPath.AssignLiteral("CLSID\\");
delegateExecuteRegPath.Append(delegateExecute);
delegateExecuteRegPath.AppendLiteral("\\LocalServer32");
rv = chkKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
delegateExecuteRegPath,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
NS_ENSURE_SUCCESS(rv, rv);
rv = chkKey->ReadStringValue(u""_ns, handlerCommand);
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
// XXX FIXME: If this fails, the UI will display the full command
// string.
// There are some rare cases this can happen - ["url.dll" -foo]
// for example won't resolve correctly to the system dir. The
// subsequent launch of the helper app will work though.
nsCOMPtr lf = new nsLocalFile();
rv = lf->InitWithCommandLine(handlerCommand);
NS_ENSURE_SUCCESS(rv, rv);
lf.forget(aDefaultApplication);
wchar_t friendlyName[1024];
DWORD friendlyNameSize = 1024;
HRESULT hr = AssocQueryString(ASSOCF_NONE, ASSOCSTR_FRIENDLYAPPNAME,
PromiseFlatString(aAppInfo).get(), NULL,
friendlyName, &friendlyNameSize);
if (SUCCEEDED(hr) && friendlyNameSize > 1) {
aDefaultDescription.Assign(friendlyName, friendlyNameSize - 1);
}
return NS_OK;
}
Minimal test - lines (198, 217)
path: .spaces[6].metrics.halstead.bugs
old: 0.03662962161471501
new: 0.0976165703925941
path: .spaces[6].metrics.halstead.difficulty
old: 8.125
new: 10.62962962962963
path: .spaces[6].metrics.halstead.length
old: 34.0
new: 88.0
path: .spaces[6].metrics.halstead.N1
old: 21.0
new: 47.0
path: .spaces[6].metrics.halstead.effort
old: 1151.9417816484386
new: 5011.49383069016
path: .spaces[6].metrics.halstead.time
old: 63.99676564713547
new: 278.41632392723113
path: .spaces[6].metrics.halstead.estimated_program_length
old: 57.219280948873624
new: 181.6849314672201
path: .spaces[6].metrics.halstead.n2
old: 8.0
new: 27.0
path: .spaces[6].metrics.halstead.n1
old: 10.0
new: 14.0
path: .spaces[6].metrics.halstead.N2
old: 13.0
new: 41.0
path: .spaces[6].metrics.halstead.purity_ratio
old: 1.6829200279080478
new: 2.064601493945683
path: .spaces[6].metrics.halstead.vocabulary
old: 18.0
new: 41.0
path: .spaces[6].metrics.halstead.volume
old: 141.7774500490386
new: 471.46457640639136
path: .spaces[6].metrics.halstead.level
old: 0.12307692307692308
new: 0.0940766550522648
path: .spaces[6].metrics.cognitive.sum
old: 1.0
new: 3.0
path: .spaces[6].metrics.cognitive.average
old: 1.0
new: 3.0
path: .spaces[6].metrics.cyclomatic.sum
old: 2.0
new: 4.0
path: .spaces[6].metrics.cyclomatic.average
old: 2.0
new: 4.0
path: .spaces[6].metrics.mi.mi_original
old: 109.18281725715585
new: 89.53874852609833
path: .spaces[6].metrics.mi.mi_sei
old: 82.02029673398083
new: 70.85970635818194
path: .spaces[6].metrics.mi.mi_visual_studio
old: 63.84960073517885
new: 52.36184124333236
path: .spaces[6].metrics.loc.blank
old: 0.0
new: 4.0
path: .spaces[6].metrics.loc.ploc
old: 9.0
new: 15.0
path: .spaces[6].metrics.loc.lloc
old: 3.0
new: 10.0
path: .spaces[6].metrics.loc.sloc
old: 9.0
new: 20.0
path: .spaces[6].metrics.loc.cloc
old: 0.0
new: 1.0
path: .spaces[6].metrics.nargs.sum
old: 3.0
new: 2.0
path: .spaces[6].metrics.nargs.average
old: 3.0
new: 2.0
path: .spaces[6].metrics.nexits.average
old: 1.0
new: 3.0
path: .spaces[6].metrics.nexits.sum
old: 1.0
new: 3.0
Code
nsresult nsOSHelperAppService::GetMIMEInfoFromRegistry(const nsString& fileType,
nsIMIMEInfo* pInfo) {
nsresult rv = NS_OK;
NS_ENSURE_ARG(pInfo);
nsCOMPtr regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) return NS_ERROR_NOT_AVAILABLE;
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, fileType,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// OK, the default value here is the description of the type.
nsAutoString description;
rv = regKey->ReadStringValue(u""_ns, description);
if (NS_SUCCEEDED(rv)) pInfo->SetDescription(description);
return NS_OK;
}