{************************************************************
 ***                                                      ***
 ***                  INSTALL KAMELEON                    ***
 ***                                                      ***
 ************************************************************}
{An Updater program for Kameleon}
{Meant for use by tekky staff when updating people to newer systems...}
{{$I compdirs}

{$IFDEF MSDOS}
	{$M $6000,0,$30000} {increase stack size a bit}
{$ELSE}
	{$M $9000} {increase stack size}
{$ENDIF}
{}

{$X+} {allows incomplete use of this type:}

program Install;

uses
			upstart,
{$IFDEF MSDOS} overlay, overinit,{} {$ENDIF}
			scodes, kbooks,
			global,
			files,
			views,
			status,
			tuimsgs,
			tuiapp,
			minilib,
			menus,
			tasks,
			update,
			alljimmy,
			fixit,
			dbg,
			{specialist modules}
			{$IFDEF KRongai} KRongai, KRongOrd, KRongai2, {$ENDIF}
			upfrom42,
			upfrom4;

{HAve to overlay or get too many relocation items}
{$O scodes} {$O kbooks} {$O kbksrpts}
{$O files}
{$O views}
{$O dialogs}
{$O status}
{$O tuimsgs}
{$O tuiapp}
{$O menus}
{$O tasks}

{$O update} {$O upfrom4} {$O upfrom42} {$O fixit} {$O alljimmy} {$O upv4objs} {$O upv4inv}

{$O kcompany} {$O kperson} {$O kdirctry} {$O kstaff} {$O kusers}
{$O kletter}{$O kmnote} {$O kinvoice} {$O ordproc} {$O kinvrpts}
{$O kmaint} {$O kstock}

{$O notes} {$O address}{$O linklist} {$O tasks}

{$O indxutil} {$O devices} {$O printers}
{$O vat} {$O indexes} {$O Idindex} {$O tables}

{$O tuimsgs} {$O tuicalc} {$O tuiboxes}
{$O views} {$O dialogs} {$O app} {$O tuiedit} {$O tuilist} {$O tui}

{$O indexes} {$O jimhooks} {$O jimindxs}{$O jimmys}
{$O multcurr}{$O dattime}{$O tuimsgs}
{$O inpjimmy}{$O tuijimmy}


{Always present, occasionally used units (so always overlay them)}
{$O forms} {$O labels}
{$O devices} {$O printers} {$O faxes} {$O modems}
{$O autodial} {$O doscom} {$O email}
{$O messtext}
{$O reports}
{$O files}
{$O tuigrphs}
{$O tuicalc} {calculator}
{$O Stddlg}
{$O MultCurr}
{$O lstrings}
{$O indxutil}
{$O video}

{$O inpjimmy}
{$O inplist}
{$O inpdnt}

{Always present, often used, but too many relocation items..}
{$O jimmys} {$O jimhooks} {$O jimindxs} {$O jimprint}
{$O linklist} {$O indexes} {$O tuijimmy}
{$O notes}


{************************************************************
 ***                 UPDATE NOTES                         ***
 ************************************************************

v4.0 onwards:
	Old accountin categories invalid (no parent).  Delete by hand.

v4.0e onwards:
	Big changes required.  New objects and sizes, addressing system, etc.
	Needs a
	fullJimmyUpdate, and a reconstruction.  Safe to do reconstruction
	as there are no "loose" jimmys at this stage (ie no jimmys in lists
	without back pointers to that list).

	Lots of files to be deleted, all *.IDX will be anyway, and WPLTRS.DAT,
	etc, etc - see UPFROM4.PAS

v4.1 onwards -
	straight get/put, addition of some index ptrs and removal of old
	TPerson & TCompany load versions (see upv4objs)

v4.2 onwards -
	added index ptr to invoice (out tray), and increased size
	of addresses.  Should also catch Kilimanjaro's QuickInvoices

{}

{**************************************************************
 ***                                                        ***
 ***               UPDATE DIAGNOSER                         ***
 ***                                                        ***
 **************************************************************}
procedure UpdateDbase; far;
var DataVer : TVer;
		Control : word;
begin
	{--- update ----}
	ProgramStatus.GetDataVer(DataVer);

	Control := MessageBox('UPDATE',
									'Database version '+N2Str(DataVer.Main)+'.'+N2Str(DataVer.Sub)+DataVer.Release
									+' Program '+N2Str(ProgVer.Main)+'.'+N2Str(ProgVer.Sub)+ProgVer.Release+#13#10
									+'HAVE YOU BACKED UP?!',
									mfOKButton or mfCancelButton or mfWarning,hcNoContext);

	if Control = cmCancel then exit;


	if False then begin
		ReconstructAll;
{		DeleteAdminFiles;
		Control := ForAllJimmys('RE-CONSTRUCT','Re-hooking & indexing',DoJimmyStoreSelf,OnNilDoStd);
		if Control<>cmOK then
			ProgramWarning('You have abandoned the reconstruction'#13'Data corrupted!',hcNoContext);{}
		exit;
	end else begin

		if (DataVer.Main=4) and ((DataVer.Sub<2) or (DataVer.Sub>100)) then begin
			UpdateFrom40;
		end;

		if (DataVer.Main=4) and (DataVer.Sub=2) then begin
			{has to do a change size for the invoices & addresses}
			FullJimmyUpdate(False, QuickInvConverter, false); {True to resort Kilimanjaro's invoices}
		end;

		if (DataVer.Main=ProgVer.Main) and (DataVer.Sub=ProgVer.Sub) then begin
			{Standard re-put, eg for after adding a new idx ptr}
			ReputJimmys;
		end;{}
	end;
	ProgramStatus.SetDataVer(ProgVer);
end;


begin
	{==== Set up application menu =====}
	AppMenu := NewMenu(nil);
	AddItemEnd(AppMenu,
		NewSubMenu('~U~pdate', kbNone, hcNoContext,
			NewMenu(
				NewItem('Update ~d~atabase', '', kbNone, cmUpdateDBase, hcNoContext,
			nil)),
		NewSubMenu('~K~ameleon', kbNone, hcNoContext,
			NewMenu(
				NewItem('Directory', '', kbNone, cmStartDirectoryList, hcNoContext,
				NewItem('Exit', '', kbNone, cmQuit, hcNoContext,
			nil))),
		NewSubMenu('~F~ixit', kbNone, hcNoContext,
			NewMenu(
				NewItem('Edit Jimmy', '', kbNone, cmEditJimmy, hcNoContext,
				NewItem('~C~heck Database',   '', kbNone, cmCheckDBase, hcNoContext,
			nil))),
		nil)))
	);

	RegisterTask(DesktopTasks, cmUpdateDBase, @UpdateDBase);

	New(Kameleon, init); {provide a nice kameleon screen}

{	UpdateDBase;{}

	Kameleon^.Run; {for testing}

	Dispose(Kameleon, done);

end.
