Пример #1
0
// Get a toolbar
ToolBarInfo *OpenToolBar(Cfg_ButtonBank *buttons,char *pathname)
{
	ToolBarInfo *toolbar;

	// Allocate toolbar structure
	if (toolbar=AllocVec(sizeof(ToolBarInfo),MEMF_CLEAR))
	{
		// Bank provided?
		if (buttons) toolbar->buttons=buttons;

		// Load disk file
		else
		if (pathname && pathname[0]) toolbar->buttons=OpenButtonBank(pathname);

		// Invalid?
		if (!toolbar->buttons ||
			!(GetToolBarCache(toolbar,FALSE)))
		{
			FreeToolBar(toolbar);
			return 0;
		}
	}

	// Bank provided? Copy pathname
	if (buttons && pathname)
		strcpy(pathname,buttons->path);


	return toolbar;
}
Пример #2
0
// Read an environment
BOOL environment_open(Cfg_Environment *env,char *name,BOOL first,APTR prog)
{
	struct OpenEnvironmentData *opendata;
	BOOL success;
	short progress=1;

	// Free volatile memory
	ClearMemHandle(env->volatile_memory);

	// Initialise open structure
	if (!(opendata=AllocMemH(env->volatile_memory,sizeof(struct OpenEnvironmentData))))
		return 0;
	opendata->memory=env->desktop_memory;
	opendata->volatile_memory=env->volatile_memory;
	opendata->flags=OEDF_ALL;


	// Initialise progress
	SetProgressWindowTags(prog,PW_FileCount,14,PW_FileNum,1,TAG_END);


	// Read environment
	if ((success=OpenEnvironment((name)?name:env->path,opendata)))
	{
		// Check stack setting and increase if too low
		if (opendata->env.default_stack < STACK_DEFAULT)
			opendata->env.default_stack = STACK_DEFAULT;

		// Copy things back to the environment
		CopyMem((char *)&opendata->env,(char *)env->env,sizeof(CFG_ENVR));
		strcpy(env->toolbar_path,opendata->toolbar_path);
		strcpy(env->menu_path,opendata->menu_path);
		strcpy(env->user_menu_path,opendata->user_menu_path);
		strcpy(env->scripts_path,opendata->scripts_path);
		strcpy(env->hotkeys_path,opendata->hotkeys_path);
		
		// Get maximum filename length
		// we have to do this before the listers are opened
		GUI->def_filename_length=environment->env->settings.max_filename;
		if (GUI->def_filename_length<FILENAME_LEN)
			GUI->def_filename_length=FILENAME_LEN;
		else
		if (GUI->def_filename_length>107)
			GUI->def_filename_length=107;
	}

	// Successful?
	if (success || first)
	{
		ButtonBankNode *button;
		OpenListerNode *lister;

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Store new environment path
		if (name) strcpy(env->path,name);

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Get new toolbar
		FreeToolBar(GUI->toolbar);
		GUI->toolbar=OpenToolBar(0,env->toolbar_path);

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Free lister menu, get new one
		CloseButtonBank(GUI->lister_menu);
		if ((GUI->lister_menu=OpenButtonBank(env->menu_path)))
		{
			// Check if it needs conversion
			if (!(GUI->lister_menu->window.flags&BTNWF_FIX_MENU))
			{
				// Convert it to new format
				ConvertStartMenu(GUI->lister_menu);
				GUI->lister_menu->window.flags|=BTNWF_FIX_MENU;
			}
		}

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Free user menu, get new one
		CloseButtonBank(GUI->user_menu);
		GUI->user_menu=OpenButtonBank(env->user_menu_path);

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Free scripts, get new set
		CloseButtonBank(GUI->scripts);
		GUI->scripts=OpenButtonBank(env->scripts_path);

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Free hotkeys, get new ones
		send_main_reset_cmd(CONFIG_CHANGE_HOTKEYS,0,0);

		// Go through buttons to open
		for (button=(ButtonBankNode *)opendata->buttons.mlh_Head;
			button->node.ln_Succ;)
		{
			ButtonBankNode *next=(ButtonBankNode *)button->node.ln_Succ;
			Buttons *but;

			// Create button bank from this node
			if ((but=buttons_new(button->node.ln_Name,0,&button->pos,0,button->flags|BUTTONF_FAIL)))
			{
				// Set icon position
				but->icon_pos_x=button->icon_pos_x;
				but->icon_pos_y=button->icon_pos_y;
			}

			// Free this node, get next
			Remove((struct Node *)button);
			FreeMemH(button->node.ln_Name);
			FreeMemH(button);
			button=next;
		}

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Go through StartMenus to open
		for (button=(ButtonBankNode *)opendata->startmenus.mlh_Head;
			button->node.ln_Succ;)
		{
			ButtonBankNode *next=(ButtonBankNode *)button->node.ln_Succ;

			// Create new start menu
			start_new(button->node.ln_Name,0,0,button->pos.Left,button->pos.Top);

			// Free this node, get next
			Remove((struct Node *)button);
			FreeMemH(button->node.ln_Name);
			FreeMemH(button);
			button=next;
		}

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Go through listers to open
		for (lister=(OpenListerNode *)opendata->listers.mlh_Head;
			lister->node.ln_Succ;)
		{
			OpenListerNode *next=(OpenListerNode *)lister->node.ln_Succ;

			// Create lister from this node
			if (lister->lister)
				lister_new((Cfg_Lister *)lister->lister);

			// Free this node, get next
			Remove((struct Node *)lister);
			FreeMemH(lister);
			lister=next;
		}

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Free existing desktop list
		env_free_desktop(&env->desktop);

		// Copy new desktop into list
		if (!(IsListEmpty((struct List *)&opendata->desktop)))
		{
			env->desktop=opendata->desktop;
			env->desktop.mlh_TailPred->mln_Succ=(struct MinNode *)&env->desktop.mlh_Tail;
			env->desktop.mlh_Head->mln_Pred=(struct MinNode *)&env->desktop.mlh_Head;
		}

		// Free existing path list
		env_free_desktop(&env->path_list);

		// Copy new pathlist into list
		if (!(IsListEmpty((struct List *)&opendata->pathlist)))
		{
			env->path_list=opendata->pathlist;
			env->path_list.mlh_TailPred->mln_Succ=(struct MinNode *)&env->path_list.mlh_Tail;
			env->path_list.mlh_Head->mln_Pred=(struct MinNode *)&env->path_list.mlh_Head;
		}

		// Free existing sound list
		env_free_desktop(&env->sound_list);

		// Copy new sound list into list
		if (!(IsListEmpty((struct List *)&opendata->soundlist)))
		{
			env->sound_list=opendata->soundlist;
			env->sound_list.mlh_TailPred->mln_Succ=(struct MinNode *)&env->sound_list.mlh_Tail;
			env->sound_list.mlh_Head->mln_Pred=(struct MinNode *)&env->sound_list.mlh_Head;
		}

		// Bump progress
		main_bump_progress(prog,progress++,0);

		// Update priority
		IPC_Command(&main_ipc,
			IPC_PRIORITY,
			env->env->settings.pri_main[1],
			(APTR)env->env->settings.pri_main[0],
			0,0);

		// Fix lister priorities
		lister_fix_priority(0);

		// Bump progress
		main_bump_progress(prog,progress++,0);
	}

	// Failed, free temp lists
	else
	{
		env_free_desktop(&opendata->desktop);
		env_free_desktop(&opendata->pathlist);
		env_free_desktop(&opendata->soundlist);
		env_free_desktop(&opendata->startmenus);
		env_free_desktop(&opendata->buttons);
		env_free_desktop(&opendata->listers);
	}

	// Free open data structure
	FreeMemH(opendata);

	// Bump progress
	main_bump_progress(prog,progress,0);

	// Build the user menu (needed even if there is none)
	display_build_user_menu();

	// Initialise progress
	SetProgressWindowTags(prog,PW_FileCount,1,PW_FileNum,1,TAG_END);

	// Set library flag for 'Move AppIcons to Tools Menu'
	SetLibraryFlags((env->env->display_options&DISPOPTF_SHIFT_APPICONS)?LIBDF_REDIRECT_TOOLS:0,LIBDF_REDIRECT_TOOLS);

	// Set library flag for borderless icons
	SetLibraryFlags((env->env->desktop_flags&DESKTOPF_NO_BORDERS)?LIBDF_BORDERS_OFF:0,LIBDF_BORDERS_OFF);

	// No icon caching?
	SetLibraryFlags((env->env->desktop_flags&DESKTOPF_NO_CACHE)?LIBDF_NO_CACHING:0,LIBDF_NO_CACHING);

	// Set NewIcons flags
	SetNewIconsFlags(env->env->env_NewIconsFlags,env->env->env_NewIconsPrecision);

	// No custom drag?
	SetLibraryFlags((env->env->desktop_flags&DESKTOPF_NO_CUSTOMDRAG)?LIBDF_NO_CUSTOM_DRAG:0,LIBDF_NO_CUSTOM_DRAG);

	// Thin borders?
	SetLibraryFlags((env->env->display_options&DISPOPTF_THIN_BORDERS)?LIBDF_THIN_BORDERS:0,LIBDF_THIN_BORDERS);

	// Update pathlist environment variable
	env_update_pathlist();

	// Set popup delay
	SetPopUpDelay(env->env->settings.popup_delay);

	// Fix MUFS library
	env_fix_mufs();

	// Assign themes path
	env_fix_themes();

	// Initialise sound events
	InitSoundEvents(TRUE);

	return success;
}
Пример #3
0
// Quit the program
void quit(BOOL script)
{
	// If main status window is open, close it
	if (main_status)
	{
		CloseProgressWindow(main_status);
		main_status=0;
	}

	if (GUI)
	{
		// Clear 'startup' flag for scripts
		GUI->flags&=~GUIF_DONE_STARTUP;

		// Close commodities
		cx_remove(GUI->cx);

		// Update environment settings
		env_update_settings(1);

		// Stop notify request
		RemoveNotifyRequest(GUI->notify_req);
		GUI->notify_req=0;

		// Is there a hide appicon?
		if (GUI->hide_appicon)
		{
			RemoveAppIcon(GUI->hide_appicon);
			FreeCachedDiskObject(GUI->hide_diskobject);
		}

		// Or an appmenuitem?
		if (GUI->hide_appitem) RemoveAppMenuItem(GUI->hide_appitem);

		// Launch shutdown script
		if (script)
			RunScript(SCRIPT_SHUTDOWN,0);

		// Set quit flag
		GUI->flags|=GUIF_PENDING_QUIT;

		// Shut the display down
		close_display(CLOSE_ALL,TRUE);

		// Send quit notifications
		quit_notify();

		// Stop notifications
		stop_file_notify(GUI->pattern_notify);
		stop_file_notify(GUI->font_notify);
		stop_file_notify(GUI->modules_notify);
		stop_file_notify(GUI->commands_notify);
		stop_file_notify(GUI->env_notify);
		stop_file_notify(GUI->desktop_notify);
		stop_file_notify(GUI->filetype_notify);

		// Free application port
		if (GUI->appmsg_port)
		{
			DOpusAppMessage *amsg;
			RemPort(GUI->appmsg_port);
			while ((amsg=(DOpusAppMessage *)GetMsg(GUI->appmsg_port)))
				ReplyAppMessage(amsg);
			DeleteMsgPort(GUI->appmsg_port);
			GUI->appmsg_port=0;

			// Remove public semaphore
			RemSemaphore((struct SignalSemaphore *)&pub_semaphore);
		}

		// Flush IPC port
		IPC_Flush(&main_ipc);

		// Close all processes
		IPC_ListQuit(&GUI->lister_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->group_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->buttons_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->startmenu_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->process_list,&main_ipc,0,TRUE);
		IPC_ListQuit(&GUI->function_list,&main_ipc,0,TRUE);

		// Free buffers
		buffers_clear(0);

		// Remove all handlers
		RemFunctionTrap("*","#?");

		// Free filetypes
		FreeMemHandle(GUI->filetype_memory);

		// Flush the filetype cache
		ClearFiletypeCache();

		// Free lister toolbar
		FreeToolBar(GUI->toolbar);

		// Free menus and hotkeys
		CloseButtonBank(GUI->lister_menu);
		CloseButtonBank(GUI->hotkeys);

		// Free user menus
		CloseButtonBank(GUI->user_menu);
		FreeVec(GUI->user_menu_data);

		// Free backdrop list
		backdrop_free(GUI->backdrop);

		// Free icons
		if (GUI->lister_icon) FreeCachedDiskObject(GUI->lister_icon);
		if (GUI->button_icon) FreeCachedDiskObject(GUI->button_icon);

		// Free arrow image
		CloseImage(GUI->toolbar_arrow_image);

#ifdef __amigaos3__
		FreeVec(arrow_hi_data_chip);
		FreeVec(arrow_lo_data_chip);
		FreeVec(small_arrow_chip);
		FreeVec(big_arrow_chip);
#ifndef USE_SCREENTITLE
		FreeVec(moon_big_data_chip);
		FreeVec(moon_small_data_chip);
#endif
		FreeVec(command_arrow_chip);
		FreeVec(parent_arrow_chip);
#endif

		// Free screen signal
		if (GUI->screen_signal!=-1) FreeSignal(GUI->screen_signal);

		// Delete notify port
		if (GUI->notify_port) DeleteMsgPort(GUI->notify_port);

		// Free position memory
		FreeMemHandle(GUI->position_memory);

		// Free command history
		Att_RemList(GUI->command_history,0);

		// Delete icon positioning port
		DeleteMsgPort(GUI->iconpos_port);

		// Free popup menu
		PopUpFreeHandle(GUI->desktop_menu);

		// Clear requester pattern hook in library
		if (GUI->flags2&GUIF2_BACKFILL_SET)
			SetReqBackFill(0,0);
	}

	// Free scripts
	FreeScripts();

	// Free environment
	environment_free(environment);
	
	// Delete main message ports
	IPC_Flush(&main_ipc);
	DeleteMsgPort(main_ipc.command_port);
	DeleteMsgPort(main_ipc.reply_port);

	// Pause here for a couple of seconds to let everything clean up
	Delay(3*50);

	// Free global data
	FreeMemHandle(global_memory_pool);

	// Delete any temporary files
	delete_temp_files(0);

	// Free locale data
	free_locale_data(&locale);

	// Close input device
	if (InputBase) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IInput);
	#endif
	CloseDevice((struct IORequest *)&input_req);
	}

	// Close timer device
	if (TimerBase) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ITimer);
	#endif
	CloseDevice((struct IORequest *)&timer_req);
	}

	// Close console device
	if (ConsoleDevice) {
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IConsole);
	#endif
	CloseDevice((struct IORequest *)&console_req);
	}

	// Close libraries
	#ifdef __amigaos4__
	DropInterface((struct Interface *)Imu);
	#endif
	CloseLibrary(muBase);
	
#ifndef __amigaos3__	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)INewIcon);
	#endif
	CloseLibrary((struct Library *)NewIconBase);
#endif

	#ifdef __amigaos4__
	DropInterface((struct Interface *)ICyberGfx);
	#endif
	CloseLibrary(CyberGfxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IAmigaGuide);
	#endif
	CloseLibrary(AmigaGuideBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDataTypes);
	#endif
	CloseLibrary(DataTypesBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IAsl);
	#endif
	CloseLibrary(AslBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IIcon);
	#endif
	CloseLibrary(IconBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDiskfont);
	#endif
	CloseLibrary(DiskfontBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IWorkbench);
	#endif
	CloseLibrary(WorkbenchBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ICommodities);
	#endif
	CloseLibrary(CxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IRexxSys);
	#endif
	CloseLibrary((struct Library *)RexxSysBase); 
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IUtility);
	#endif
	CloseLibrary(UtilityBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IGadTools);
	#endif
	CloseLibrary(GadToolsBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)ILayers);
	#endif
	CloseLibrary((struct Library *)LayersBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IGraphics);
	#endif
	CloseLibrary((struct Library *)GfxBase);
	
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IIntuition);
	#endif
	CloseLibrary((struct Library *)IntuitionBase);
	
	// Restore old current directory?
	if (old_current_dir)
	{
		UnLock(CurrentDir(old_current_dir));
	}

	// Close the dopus5.library
	#ifdef __amigaos4__
	DropInterface((struct Interface *)IDOpus);
	#endif
	CloseLibrary(DOpusBase);

	// Outahere!
	exit(0);
}
Пример #4
0
// Cleanup a lister
void lister_cleanup(Lister *lister,BOOL bye)
{
	struct Node *node;

	// Send goodbye message?
	if (bye)
	{
		// Update our position
		if (!(environment->env->lister_options&LISTEROPTF_SNAPSHOT))
			PositionUpdate(lister,0);

		// Send goodbye message
		IPC_Goodbye(lister->ipc,&main_ipc,WINDOW_LISTER);
	}

	// Is lister iconified?
	if (lister->appicon)
	{
		// Remove AppIcon
		RemoveAppIcon(lister->appicon);

		// Free icon
		FreeDiskObjectCopy(lister->appicon_icon);
	}

	// If we still have a progress window, close it
	lister_progress_off(lister);

	// Showing a special buffer?
	if (lister->cur_buffer==lister->special_buffer)
	{
		// Return to normal
		lister->cur_buffer=lister->old_buffer;
	}

	// Remove buffer lock
	if (lister->cur_buffer)
	{
		// Get buffer list lock
		lock_listlock(&GUI->buffer_list,TRUE);

		// Unlock buffer
		buffer_clear_lock(lister->cur_buffer,1);

		// If buffer is empty or buffer count exceeds maximum, free it
		if (lister->cur_buffer->buf_TotalEntries[0]==0 ||
			GUI->buffer_count>environment->env->settings.max_buffer_count ||
			(environment->env->settings.dir_flags&DIRFLAGS_DISABLE_CACHING))
		{
			// Free buffer
			lister_free_buffer(lister->cur_buffer);
		}

		// Unlock buffer list
		unlock_listlock(&GUI->buffer_list);
	}

	// Free user data
	while ((node=lister->user_data_list.list.lh_Head)->ln_Succ)
	{
		Remove(node);
		FreeMemH(node);
	}

	// Free ports
	if (lister->app_port)
	{
		DOpusAppMessage *msg;
		while ((msg=(DOpusAppMessage *)GetMsg(lister->app_port)))
			ReplyAppMessage(msg);
		DeleteMsgPort(lister->app_port);
	}

	// Close font
	if (lister->font)
		CloseFont(lister->font);	

	// Free signals
	if (lister->abort_signal!=-1)
		FreeSignal(lister->abort_signal);
	if (lister->hot_name_bit!=-1)
		FreeSignal(lister->hot_name_bit);

	// Free timer stuff
	if (lister->timer_port)
	{
		// Close timers
		FreeTimer(lister->foo_timer);
		FreeTimer(lister->icon_drag_timer);
		FreeTimer(lister->busy_timer);
		FreeTimer(lister->edit_timer);
		FreeTimer(lister->scroll_timer);

		// Delete timer port
		DeleteMsgPort(lister->timer_port);
	}

	// Free regions
	if (lister->title_region) DisposeRegion(lister->title_region);
	if (lister->refresh_extra) DisposeRegion(lister->refresh_extra);

	// Free special buffer
	if (lister->special_buffer) buffer_free(lister->special_buffer);

	// Free reselection
	FreeReselect(&lister->reselect);

	// Free history
	Att_RemList(lister->path_history,0);

	// Free popup menu
	PopUpFreeHandle(lister->lister_tool_menu);

	// Free toolbar
	FreeToolBar(lister->toolbar_alloc);

	// Free IPC data
	IPC_Free(lister->ipc);

	// Free lister data
	lister_free(lister);

	// Decrement count
	--main_lister_count;
}