// Free a toolbar void FreeToolBar(ToolBarInfo *toolbar) { // Valid toolbar? if (toolbar) { // Free cache FreeToolBarCache(toolbar); // Free buttons CloseButtonBank(toolbar->buttons); // Free position array FreeVec(toolbar->button_array); // Free data FreeVec(toolbar); } }
// 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); }
// Load a new bank into open buttons window void buttons_new_bank(Buttons *buttons,short func,Cfg_ButtonBank *use_bank) { Cfg_ButtonBank *bank; IPCData *ipc; // Check for change if (!buttons_check_change(buttons,1)) return; // Save old bank pointer bank=buttons->bank; // New? if (func==MENU_TOOLBAR_BUTTONS_NEW) { // Create new button bank if (!(buttons->bank=NewButtonBank(1,1))) { // Restore old pointer buttons->bank=bank; return; } // Free old bank CloseButtonBank(bank); } // Load? else if (func==MENU_OPEN_BUTTONS_LOCAL) { // Open button bank if (!(buttons_load(buttons,GUI->screen_pointer,0))) return; } // Defaults else if (func==MENU_TOOLBAR_RESET_DEFAULTS) { // Open button bank if (!(buttons_load(buttons,GUI->screen_pointer,"dopus5:buttons/toolbar_default"))) return; } // Restore else if (func==MENU_TOOLBAR_RESTORE) { // Copy backup bank if (!(buttons->bank=CopyButtonBank(buttons->backup))) { // Restore old pointer buttons->bank=bank; return; } // Free old bank CloseButtonBank(bank); } // Last saved else if (buttons->last_saved[0]) { // Open button bank if (!(buttons_load(buttons,GUI->screen_pointer,buttons->last_saved))) return; } // Lock process list lock_listlock(&GUI->process_list,FALSE); // Find editor if ((ipc=IPC_FindProc(&GUI->process_list,NAME_BUTTON_EDITOR_RUN,0,0))) { // Set flag in bank buttons->bank->window.flags|=BTNWF_TOOLBAR; // Tell editor to change bank pointer IPC_Command( buttons->editor, BUTTONEDIT_CHANGE_BANK, (ULONG)bank, buttons->bank, 0, REPLY_NO_PORT); } // Unlock the process list unlock_listlock(&GUI->process_list); // Signal for re-open IPC_Command(buttons->ipc,BUTTONEDIT_REOPEN,0,0,0,0); // Clear change flag buttons->flags&=~BUTTONF_CHANGED; }
// 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; }