예제 #1
0
파일: fileio.c 프로젝트: seank/MegaTunix
G_MODULE_EXPORT gboolean select_file_for_ecu_restore(GtkWidget *widget, gpointer data)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	extern gconstpointer *global_data;

	if (!DATA_GET(global_data,"interrogated"))
		return FALSE;

	fileio = g_new0(MtxFileIO ,1);
	fileio->external_path = g_strdup("MTX_ecu_snapshots");
	fileio->parent = lookup_widget_f("main_window");
	fileio->on_top = TRUE;
	fileio->title = g_strdup("Restore your ECU Settings from which file");
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;
	fileio->shortcut_folders = g_strdup("ecu_snapshots,MTX_ecu_snapshots");

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar_f("tools_view","warning",_("NO FILE chosen for ECU restore\n"),FALSE,FALSE,FALSE);
		return FALSE;
	}
	update_logbar_f("tools_view",NULL,_("Full Restore of ECU Initiated\n"),FALSE,FALSE,FALSE);
	restore_all_ecu_settings(filename);
	g_free(filename);
	free_mtxfileio(fileio);
	return TRUE;

}
예제 #2
0
G_MODULE_EXPORT gboolean select_vex_for_export(GtkWidget *widget, gpointer data)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	GIOChannel *iochannel = NULL;
	struct tm *tm = NULL;
	time_t *t = NULL;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");

	if (!DATA_GET(global_data,"interrogated"))
		return FALSE;

	t = g_malloc(sizeof(time_t));
	time(t);
	tm = localtime(t);
	g_free(t);


	fileio = g_new0(MtxFileIO ,1);
	fileio->external_path = g_strdup("MTX_VexFiles");
	fileio->title = g_strdup("Save your VEX file");
	fileio->parent = lookup_widget_f("main_window");
	fileio->on_top = TRUE;
	fileio->default_filename= g_strdup("VEX_Backup.vex");
	fileio->default_filename= g_strdup_printf("%s-%.4i%.2i%.2i%.2i%.2i.vex",g_strdelimit(firmware->name," ,",'_'),tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
	fileio->default_extension= g_strdup("vex");
	fileio->action = GTK_FILE_CHOOSER_ACTION_SAVE;

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar_f("tools_view","warning",_("NO FILE chosen for VEX export\n"),FALSE,FALSE,FALSE);
		return FALSE;
	}

	iochannel = g_io_channel_new_file(filename, "a+",NULL);
	if (!iochannel)
	{
		update_logbar_f("tools_view","warning",_("File open FAILURE! \n"),FALSE,FALSE,FALSE);
		return FALSE;
	}
	if (vex_comment == NULL)
		update_logbar_f("tools_view",NULL,_("VEX File Opened. VEX Comment undefined, exporting without one.\n"),FALSE,FALSE,FALSE);
	else
		update_logbar_f("tools_view",NULL,_("VEX File Opened. VEX Comment already stored.\n"),FALSE,FALSE,FALSE);
	all_table_export(iochannel);
	g_io_channel_shutdown(iochannel,TRUE,NULL);
	g_io_channel_unref(iochannel);
	free_mtxfileio(fileio);
	return TRUE;
}
예제 #3
0
/*! 
  \brief select_datalog_for_import() loads a datalog file for playback
  \param widget is the Calling widget
  \param data is unused
  */
G_MODULE_EXPORT gboolean select_datalog_for_import(GtkWidget *widget, gpointer data)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	GIOChannel *iochannel = NULL;

	ENTER();
	reset_logviewer_state();
	free_log_info((Log_Info *)DATA_GET(global_data,"log_info"));

	fileio = g_new0(MtxFileIO ,1);
	fileio->default_path = g_strdup(DATALOG_DATA_DIR);
	fileio->project = (const gchar *)DATA_GET(global_data,"project_name");
	fileio->parent = lookup_widget("main_window");
	fileio->on_top = TRUE;
	fileio->title = g_strdup("Choose a datalog to view");
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar("dlog_view","warning",_("NO FILE opened for logviewing!\n"),FALSE,FALSE,FALSE);
		EXIT();
		return FALSE;
	}

	iochannel = g_io_channel_new_file(filename, "r+",NULL);
	if (!iochannel)
	{
		update_logbar("dlog_view","warning",_("File open FAILURE! \n"),FALSE,FALSE,FALSE);
		EXIT();
		return FALSE;
	}

	update_logbar("dlog_view",NULL,_("DataLog ViewFile Opened\n"),FALSE,FALSE,FALSE);
	load_logviewer_file(iochannel);
	g_io_channel_shutdown(iochannel,FALSE,NULL);
	g_io_channel_unref(iochannel);

	update_logbar("dlog_view",NULL,_("LogView File Closed\n"),FALSE,FALSE,FALSE);
	gtk_widget_set_sensitive(lookup_widget("logviewer_controls_hbox"),TRUE);
	enable_playback_controls(TRUE);
	free_mtxfileio(fileio);
	EXIT();
	return TRUE;
}
예제 #4
0
/*!
  \brief initiates an offline ECU restore from file. Prompts for file, if
  valid, it calles the restore_all function from the ECU plugin
  */
G_MODULE_EXPORT void offline_ecu_restore_pf(void)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	void (*restore_all_f)(const gchar *);
	Firmware_Details *firmware = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	get_symbol("restore_all_ecu_settings",(void **)&restore_all_f);

	g_return_if_fail(firmware);
	g_return_if_fail(restore_all_f);

	if (!DATA_GET(global_data,"interrogated"))
	{
		EXIT();
		return;
	}

	fileio = g_new0(MtxFileIO ,1);
	fileio->default_path = g_strdup(BACKUP_DATA_DIR);
	fileio->project = (const gchar *)DATA_GET(global_data,"project_name");
	fileio->parent = lookup_widget("main_window");
	fileio->on_top = TRUE;
	fileio->title = g_strdup("You should load an ECU backup from a file");
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;
	fileio->shortcut_folders = g_strdup(BACKUP_DATA_DIR);
	if (DATA_GET(global_data,"last_offline_filename"))
	fileio->default_filename = g_strdup((gchar *)DATA_GET(global_data,"last_offline_filename"));

	filename = choose_file(fileio);
	if (filename)
	{
		DATA_SET_FULL(global_data,"last_offline_filename",g_strdup(filename),g_free);
		update_logbar("tools_view",NULL,_("Full Restore of ECU Initiated\n"),FALSE,FALSE,FALSE);
		restore_all_f(filename);
		g_free(filename);
	}
	else
		io_cmd(firmware->get_all_command,NULL);

	free_mtxfileio(fileio);
	EXIT();
	return;
}
예제 #5
0
G_MODULE_EXPORT void select_table_for_import(gint table_num)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	GIOChannel *iochannel = NULL;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");

	if (!DATA_GET(global_data,"interrogated"))
		return;

	if ((table_num < 0) || (table_num >= firmware->total_tables))
		return;

	fileio = g_new0(MtxFileIO ,1);
	fileio->external_path = g_strdup("MTX_VexFiles");
	fileio->parent = lookup_widget_f("main_window");
	fileio->on_top = TRUE;
	fileio->title = g_strdup("Select your VEX file to import");
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar_f("tools_view","warning",_("NO FILE chosen for VEX import\n"),FALSE,FALSE,FALSE);
		return;
	}

	iochannel = g_io_channel_new_file(filename, "r+",NULL);
	if (!iochannel)
	{
		update_logbar_f("tools_view","warning",_("File open FAILURE! \n"),FALSE,FALSE,FALSE);
		return;
	}
	update_logbar_f("tools_view",NULL,_("VEX File Closed\n"),FALSE,FALSE,FALSE);
	gtk_entry_set_text(GTK_ENTRY(lookup_widget_f("tools_vex_comment_entry")),"");

	single_table_import(iochannel,table_num);
	g_io_channel_shutdown(iochannel,TRUE,NULL);
	g_io_channel_unref(iochannel);
	free_mtxfileio(fileio);
	return;
}
예제 #6
0
파일: fileio.c 프로젝트: seank/MegaTunix
G_MODULE_EXPORT gboolean select_file_for_ecu_backup(GtkWidget *widget, gpointer data)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	struct tm *tm = NULL;
	time_t *t = NULL;
	extern gconstpointer *global_data;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");


	if (!DATA_GET(global_data,"interrogated"))
		return FALSE;

	t = g_malloc(sizeof(time_t));
	time(t);
	tm = localtime(t);
	g_free(t);

	fileio = g_new0(MtxFileIO ,1);
	fileio->external_path = g_strdup("MTX_ecu_snapshots");
	fileio->title = g_strdup("Save your ECU Settings to file");
	fileio->parent = lookup_widget_f("main_window");
	fileio->on_top = TRUE;
	fileio->default_filename = g_strdup_printf("%s-%.4i_%.2i_%.2i-%.2i%.2i.ecu",g_strdelimit(firmware->name," ,",'_'),tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
	fileio->default_extension = g_strdup("ecu");
	fileio->action = GTK_FILE_CHOOSER_ACTION_SAVE;
	fileio->shortcut_folders = g_strdup("MTX_ecu_snapshots");

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar_f("tools_view","warning",_("NO FILE chosen for ECU Backup\n"),FALSE,FALSE,FALSE);
		return FALSE;
	}
	update_logbar_f("tools_view",NULL,_("Full Backup of ECU Initiated\n"),FALSE,FALSE,FALSE);
	backup_all_ecu_settings(filename);
	update_logbar_f("tools_view",NULL,_("Full Backup File Closed\n"),FALSE,FALSE,FALSE);
	g_free(filename);
	free_mtxfileio(fileio);
	return TRUE;
}