DefConst('upgradePrefs,
	func(prefs)
	begin
		if prefs.version = 1 then
		begin
			prefs.mark := $;
			prefs.version := 2;
		end;
		
		EntryChange(prefs);
	end);

InstallScript := func (partFrame, removeFrame)
begin
	local tTemplate :=
		EnsureInternal({_proto: nil, Drag: nil, buttonToggle: nil, tag: kAppSymbol});
	tTemplate._proto := GetRoot()._proto;
	tTemplate.(kAppSymbol) := tTemplate;
	tTemplate.Drag := newDrag;
	tTemplate.buttonToggle := newButtonToggle;
	GetRoot()._proto := tTemplate;
	
	RegPrefs(kAppSymbol, GetLayout("prefs.t"));
	SetValue(GetRoot(), EnsureInternal(kAppSymbol), {});
	local ourPrefs := GetAppPrefs(kAppSymbol, kDefaultPrefs);
	if ourPrefs.version < kDefaultPrefs.version then
		call upgradePrefs with (ourPrefs);
	GetRoot().(kAppSymbol).prefs := ourPrefs;
	GetRoot().(kAppSymbol).SharewareFee := 5;
	GetRoot().(kAppSymbol).version := kVersionString;

	if not (GlobalVarExists(kNameCache)) then
		DefGlobalVar(kNameCache, {});
end;

RemoveScript := func (removeFrame)
begin
	if (GetRoot()._proto.(kAppSymbol)) then
		ReplaceObject(GetRoot()._proto.(kAppSymbol), GetRoot()._proto.(kAppSymbol)._proto);
	
	UnRegPrefs(kAppSymbol);
	RemoveSlot(GetRoot(), kAppSymbol);
end;
