/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" #include "version.h" #include "sabbu.h" #include "sound.h" #include "gui_splash.h" #include "sound_out.h" #include "gui_main_script.h" #include "gui_main_style_manager.h" #include "gui_workspace.h" #include "sub_preview.h" #include "kryString.h" #include "stringutils.h" #include "spell.h" #ifdef _WINDOWS extern int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS pExceptPtrs, LPCTSTR lpszMessage); #endif struct sabbu app; krySabbu *appObj = NULL; gboolean sabbu_key_snooper(GtkWidget *widget, GdkEventKey *event, gpointer data) { if(event->type != GDK_KEY_PRESS) return FALSE; if(event->keyval == GDK_F2) { if(gui_main_is_enabled()) gui_main_menu_script_save(NULL, 0); return TRUE; } if(event->keyval == GDK_F3) { if(gui_main_is_enabled()) gui_find_replace_find(); return TRUE; } return FALSE; } #ifdef _WINDOWS #ifdef _DEBUG #define USEMAIN #else #define USECRASHHANDLER #endif #else #define USEMAIN #endif int sabbu_main() { #ifdef USECRASHHANDLER int nResult = -1; __try { gtk_main (); gdk_threads_leave(); } __except(RecordExceptionInfo(GetExceptionInformation(), "WinMain")) { } return nResult; #else gtk_main (); gdk_threads_leave(); #endif return 0; } #ifdef USEMAIN int main (int argc, char **argv) #else int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #endif { int i; gboolean nologo = FALSE; GList *files = NULL; #ifdef _WINDOWS #ifndef USEMAIN int argc; char **argv; #endif #endif #ifndef DISABLE_GETTEXT char *full = NULL; #ifdef _WINDOWS char exepath[_MAX_PATH]; if(GetModuleFileName(NULL, exepath, _MAX_PATH)) { char *dir = g_path_get_dirname(exepath); #ifndef _DEBUG full = kry_strdup_printf(KRY_LOC "%s\\locale", dir); #else full = kry_strdup_printf(KRY_LOC "C:\\Program Files\\sabbu\\locale"); #endif kry_free(dir); } #else full = kry_strdup(PACKAGE_LOCALE_DIR); #endif //char codepage[7]; //GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE, codepage, 7); setlocale (LC_ALL, ""); bindtextdomain ("sabbu", full); bind_textdomain_codeset("sabbu", "UTF-8"); textdomain ("sabbu"); #endif kry_malloc_enable_track(); #ifdef _WINDOWS { char exepath[_MAX_PATH]; if(GetModuleFileName(NULL, exepath, _MAX_PATH)) { char *dir = KRY_TS(g_path_get_dirname(exepath)); chdir(dir); kry_free(dir); } else { gui_warning(_("Unable to determine path to executable")); } } #endif appObj = new krySabbu(); memset(&app, 0, sizeof(struct sabbu)); char *version_extra = NULL; if(VERSION_BETA > 0) version_extra = g_strdup_printf("-BETA%d", VERSION_BETA); else version_extra = g_strdup(""); app.version = kry_strdup_printf(KRY_LOC "%d.%d.%d%s", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO, version_extra); kry_free(version_extra); char *dir = sabbu_get_config_dir(); char *file = sabbu_get_config_file(); struct _stat cfg; if(stat(dir, &cfg) < 0) { #ifdef _WINDOWS mkdir (dir); #else mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); #endif } kry_free(file); kry_free(dir); app.prefs = new kryPrefManager(); app.prefs->PushSection("Settings"); char *config_file = sabbu_get_config_file(); app.prefs->SetFilename(config_file); app.prefs->Load(); kry_free(config_file); #ifdef _WINDOWS gchar **rcfiles = gtk_rc_get_default_files(); while(rcfiles[0] != NULL) { app.ui.rc_files = g_list_append(app.ui.rc_files, kry_strdup(rcfiles[0])); rcfiles++; } #endif gtk_rc_add_default_file("sabbu.gtkrc"); #ifdef USEMAIN gtk_init (&argc, &argv); #else argc = __argc; argv = __argv; gtk_init (&__argc, &__argv); #endif gen_crc_table(); // Add our own rc file that allows us to set alternate colors on the events list for(i = 1; i < argc; i++) if(!strcmp(argv[i], "--nosplash")) nologo = TRUE; else files = g_list_append(files, g_locale_to_utf8(argv[i], -1, NULL, NULL, NULL)); g_thread_init(NULL); gdk_threads_init(); gdk_threads_enter(); spell_init(); gui_main_create(); int pos = app.prefs->GetInt("PanePositionVideoB", 0); if(pos) app.ui.pane_video_pos = pos; char *ver_no_beta = kry_strdup_printf(KRY_LOC "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO); char *last_splash_version = app.prefs->GetString("SplashVersion"); if(!last_splash_version || strcmp(last_splash_version, ver_no_beta)) { app.prefs->SetString("SplashVersion", ver_no_beta); app.prefs->SetInt("SplashCount", 0); } else if(!nologo) { int splashc = app.prefs->GetInt("SplashCount", 0); if(splashc == 3) nologo = TRUE; else app.prefs->SetInt("SplashCount", splashc + 1); } kry_free(ver_no_beta); if(!nologo) gui_main_disable(); gui_main_check_theme(); gui_main_title_update(); if(!nologo) { gui_splash_show(); gui_main_enable(); } sound_init(); soundserver_init(); #ifdef DISABLE_FFMPEG app.opts.video_disabled = TRUE; #else try { video_init(); } catch(kryError error) { gui_error(error.GetMessage()); app.opts.video_disabled = TRUE; } #endif GList *files_orig = files; for(; files; files = files->next) { if(gui_workspace_open((char *) files->data)) continue; if(appObj->ScriptOpen((char *) files->data)) continue; gui_warning(_("Unknown file format: %s"), files->data); kry_free(files->data); } g_list_free(files_orig); gtk_key_snooper_install(sabbu_key_snooper, NULL); return sabbu_main(); } void sabbu_exit() { delete app.prefs; kry_free(app.version); for(int i = 0; i < app.ui.list_color_table->GetColorCount(); i++) { kryColor *color = app.ui.list_color_table->Get(i); kry_free(color->GetUserData()); } kry_free(app.ui.info_start_less1); kry_free(app.ui.info_start_less10); kry_free(app.ui.info_start_more1); kry_free(app.ui.info_start_more10); kry_free(app.ui.info_end_less1); kry_free(app.ui.info_end_less10); kry_free(app.ui.info_end_more1); kry_free(app.ui.info_end_more10); g_list_foreach(app.ui.list_recent_scripts, (GFunc) kry_free_minimal, NULL); g_list_free(app.ui.list_recent_scripts); g_list_foreach(app.ui.list_recent_workspaces, (GFunc) kry_free_minimal, NULL); g_list_free(app.ui.list_recent_workspaces); g_list_foreach(app.ui.list_recent_audio, (GFunc) kry_free_minimal, NULL); g_list_free(app.ui.list_recent_audio); g_list_foreach(app.ui.list_recent_videos, (GFunc) kry_free_minimal, NULL); g_list_free(app.ui.list_recent_videos); kryListIterator iter; app.ui.clipboard_events.GetIterator(&iter); while(kryEventDetailed *event = iter.GetNext()) delete event; #ifdef _WINDOWS subtest_destroy(); #endif kry_malloc_print_unfreed(); sabbu_log_close(); #ifdef _WINDOWS _CrtSetReportMode(_CRT_WARN, 0); #endif exit(0); }