#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# File name: troubleshooting.kmm
#
# ---------- To check for user write priviledge on current profile -----
#
# Dependencies	: main.kmm
# Resources		: priviledge.ini, priviledge.htm, large-alert.png
# Version		: 0.3  10/30/10
# Author		: JamesD & desga2 modifications
# ----------------------------------------------------------------------

_Priviledge_RunCode {
macroinfo=_("Check KM profile write priviledge");
$_Priviledge_Path = getfolder(ProfileFolder);
$_Priviledge_Section = "Profile";
$_Priviledge_Key = "Current" ;
$_Priviledge_End = index($_Priviledge_Path,".");
$_Priviledge_Start = $_Priviledge_End - 1;
while($_Priviledge_Start < $_Priviledge_End) {
	$_Priviledge_Char = substr($_Priviledge_Path,$_Priviledge_Start,1);
	if ($_Priviledge_Char != "\\") {
		$_Priviledge_Start=$_Priviledge_Start-1;
		} else {
		$_Priviledge_Value = substr($_Priviledge_Path,$_Priviledge_Start + 1, 8);
		$_Priviledge_Start = $_Priviledge_End +1;
	}
}
$_Priviledge_Path = $_Priviledge_Path . "\\Priviledge.ini";
iniwrite($_Priviledge_Section, $_Priviledge_Key, $_Priviledge_Value, $_Priviledge_Path);
macros(_Priviledge_Validate);
}

_Priviledge_Validate {
# Value remains after delete because iniread is reading cached info in registry
$_Priviledge_Value2 = iniread("","","","");
$_Priviledge_Value2 = iniread($_Priviledge_Section, $_Priviledge_Key, $_Priviledge_Value2, $_Priviledge_Path);
if ($_Priviledge_Value != $_Priviledge_Value2) {
	$_Priviledge_WarnPath="about:mozilla";
	opennew($_Priviledge_WarnPath);
	} else {
	exec("cmd /c ERASE \"".$_Priviledge_Path."\"");
	exec("command /c ERASE \"".$_Priviledge_Path."\"");
	statusbar(_("KM profile priviledge checked successfully"));
	alert(_("KM profile priviledge checked successfully."), _("Check Priviledge"), INFO);
}
}

_Troubleshooting_BuildMenu {
setmenu(KMDocs, popup, _("Troubleshooting"), -1);
setmenu(_("Troubleshooting"), macro, _("Check Priviledge"), _Priviledge_RunCode);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$OnInit=$OnInit."_Troubleshooting_BuildMenu;";
$macroModules=$macroModules."Troubleshooting;";