Exemplo n.º 1
0
IniFile::IniFile(pcchar file, bool in_cwd)
{
    if (! in_cwd) m_file = strdup(file);
    else {
        get_app_path(_tmpbuff_,BUFSZ);
        strcat(_tmpbuff_,"/");
        strcat(_tmpbuff_,file);
        m_file = strdup(_tmpbuff_);
    }
#ifndef WIN32_INI
	FILE *in = fopen(file,"r");
	while (! feof(in)) {
		fgets(_tmpbuff_,BUFSZ,in);
		trim_end(_tmpbuff_);
		if (*_tmpbuff_ == ';' || *_tmpbuff_ == '\0')
			continue;
		if (*_tmpbuff_ == '[') {
			char* section = _tmpbuff_ + 1;
			trim_end(section);
		}
	}
	fclose(in);

#endif
}
Exemplo n.º 2
0
void log_text(const char* fmt, ...)
{
	static char path [MAX_PATH];
	static int  init = 0;
	static int  sz;
	FILE* f;
	va_list vl;

	if(init == 0)
	{
		time_t  t = time(NULL);
		get_app_path(path, sizeof(path));
		sz = strlen(path);
		sz+=snprintf(path+sz, sizeof(path)-sz, "/../log");
		mkdir(path, 0755);
		struct tm*  lt = localtime(&t);
		sz+=snprintf(path+sz, sizeof(path)-sz, "/logic_%04d%02d%02d_%02d%02d%02d.log", 
			lt->tm_year+1900,lt->tm_mon+1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
		init = 1;

		log_text("=========================== LOG START  ======================\n%s", ctime(&t));
	}

	f = fopen(path, "a+");

	if(f)
	{
		va_start(vl, fmt);
		vfprintf(f, fmt, vl);
		va_end(vl);

		fclose(f);
	}
}
// main
int
main(int argc, char **argv)
{
	// find app file and get signature from resources
	char path[B_PATH_NAME_LENGTH];
	status_t error = get_app_path(path);
	char signature[B_MIME_TYPE_LENGTH];
	if (error == B_OK) {
		// init app file
		BFile file;
		error = file.SetTo(path, B_READ_ONLY);
		// get signature
		BString signatureString;
		if (error == B_OK) {
			if (file.ReadAttrString("signature", &signatureString) == B_OK
				&& signatureString.Length() > 0) {
				strcpy(signature, signatureString.String());
			} else
				strcpy(signature, kDefaultTestAppSignature);
		} else
			printf("ERROR: Couldn't init app file: %s\n", strerror(error));
	} else
		printf("ERROR: Couldn't get app ref: %s\n", strerror(error));
	// create the app
	TestApp *app = NULL;
	if (error == B_OK) {
		app = new TestApp(signature);
//		unitTesterMessenger = BMessenger(kUnitTesterSignature);
		error = init_unit_tester_messenger();
		if (error != B_OK)
			printf("ERROR: Couldn't init messenger: %s\n", strerror(error));
		// send started message
		BMessage message(MSG_STARTED);
		message.AddString("path", path);
		unitTesterMessenger.SendMessage(&message);
		// send main() args message
		BMessage argsMessage(MSG_MAIN_ARGS);
		argsMessage.AddInt32("argc", argc);
		for (int i = 0; i < argc; i++)
			argsMessage.AddString("argv", argv[i]);
		unitTesterMessenger.SendMessage(&argsMessage);
		// run the app
		app->Run();
		delete app;
		// send terminated message
		unitTesterMessenger.SendMessage(MSG_TERMINATED);
	}
	return 0;
}
Exemplo n.º 4
0
/*!	\brief Returns an entry_ref referring to an application's executable.
	\param team The application's team ID.
	\param ref A pointer to a pre-allocated entry_ref to be initialized
		   to an entry_ref referring to the application's executable.
	\param traverse If \c true, the function traverses symbolic links.
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \c NULL \a ref.
	- another error code
*/
status_t
get_app_ref(team_id team, entry_ref *ref, bool traverse)
{
	status_t error = (ref ? B_OK : B_BAD_VALUE);
	char appFilePath[B_PATH_NAME_LENGTH];

	if (error == B_OK)
		error = get_app_path(team, appFilePath);

	if (error == B_OK) {
		BEntry entry(appFilePath, traverse);
		error = entry.GetRef(ref);
	}

	return error;
}
Exemplo n.º 5
0
static int32 expand_dir(char* buffer, const char* dir)
{
	int32 size=0;
	while( dir && *dir ) {
		if( *dir == '%' ) {
			dir++;
			switch( *dir ) {
				case '%':
					break;
				case 'A': {
					BPath path;
					if( get_app_path(&path) == B_NO_ERROR ) {
						if( path.GetParent(&path) == B_NO_ERROR ) {
							const char* dir = path.Path();
							if( dir ) {
								ArpD(cdb << ADH << "App dir = " << dir << endl);
								int len = strlen(dir);
								size += len;
								if( buffer ) {
									memcpy(buffer,dir,len);
									buffer += len;
								}
							}
						}
					}
					dir++;
				} break;
				case 0:
					if( buffer ) *buffer = 0;
					return size+1;
				default:
					dir++;
					break;
			}
		}
		if( buffer ) *(buffer++) = *dir;
		dir++;
		size++;
	}
	if( buffer ) *buffer = 0;
	return size+1;
}
Exemplo n.º 6
0
/*!	\brief Returns the path to the application's executable.
	\param buffer A pointer to a pre-allocated character array of at least
		   size B_PATH_NAME_LENGTH to be filled in by this function.
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \c NULL \a buffer.
	- another error code
*/
status_t
get_app_path(char *buffer)
{
	return get_app_path(B_CURRENT_TEAM, buffer);
}
Exemplo n.º 7
0
Arquivo: start.c Projeto: TrTLE/core
SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
{
    sal_Bool bSentArgs = sal_False;
    const char* pUsePlugin;
    rtl_uString *pPipePath = NULL;
    Args *args;
    int status = 0;
    struct splash* splash = NULL;
    struct sigaction sigpipe_action;
    struct sigaction sigterm_action;

    /* turn SIGPIPE into an error */
    memset(&sigpipe_action, 0, sizeof(struct sigaction));
    sigpipe_action.sa_handler = SIG_IGN;
    sigemptyset(&sigpipe_action.sa_mask);
    sigaction(SIGPIPE, &sigpipe_action, NULL);
    memset(&sigterm_action, 0, sizeof(struct sigaction));
    sigterm_action.sa_handler = &sigterm_handler;
    sigemptyset(&sigterm_action.sa_mask);
    sigaction(SIGTERM, &sigterm_action, NULL);

    args = args_parse ();
    args->pAppPath = get_app_path( argv[0] );
    if ( !args->pAppPath )
    {
        fprintf( stderr, "ERROR: Can't read app link\n" );
        exit( 1 );
    }

#ifndef ENABLE_QUICKSTART_LIBPNG
    /* we can't load and render it anyway */
    args->bInhibitSplash = sal_True;
#endif

    pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );
    if ( pUsePlugin && !strcmp(pUsePlugin, "svp") )
        args->bInhibitSplash = sal_True;

    if ( !args->bInhibitPipe && getenv("LIBO_XDGAPP") == NULL )
    {
        int fd = 0;
        pPipePath = get_pipe_path( args->pAppPath );

        if ( ( fd = connect_pipe( pPipePath ) ) >= 0 )
        {
            // Wait for answer
            char resp[ strlen( "InternalIPC::SendArguments" ) + 1];
            ssize_t n = read( fd, resp, SAL_N_ELEMENTS( resp ) );
            if (n == (ssize_t) SAL_N_ELEMENTS( resp )
                && (memcmp(
                resp, "InternalIPC::SendArguments",
                SAL_N_ELEMENTS( resp ) - 1) == 0)) {
                rtl_uString *pCwdPath = NULL;
                osl_getProcessWorkingDir( &pCwdPath );

                // Then send args
                bSentArgs = send_args( fd, pCwdPath );
           }

            close( fd );
        }
    }

    if ( !bSentArgs )
    {
        /* we have to prepare for, and exec the binary */
        int nPercent = 0;
        ChildInfo *info;
        sal_Bool bAllArgs = sal_True;
        sal_Bool bShortWait, bRestart;

        /* sanity check pieces */
        system_checks();

        /* load splash image and create window */
        if ( !args->bInhibitSplash )
        {
            splash = splash_create(args->pAppPath, argc, argv);
        }

        /* pagein */
        if (!args->bInhibitPagein)
            exec_pagein (args);

        /* javaldx */
#if HAVE_FEATURE_JAVA
        if (!args->bInhibitJavaLdx)
            exec_javaldx (args);
#endif

        do
        {
            bRestart = sal_False;

            /* fast updates if we have somewhere to update it to */
            bShortWait = splash ? sal_True : sal_False;

            /* Periodically update the splash & the percent according
               to what status_fd says, poll quickly only while starting */
            info = child_spawn (args, bAllArgs, bShortWait);
            g_pProcess = info->child;
            while (!child_exited_wait (info, bShortWait))
            {
                ProgressStatus eResult;

                splash_draw_progress( splash, nPercent );
                eResult = read_percent( info, &nPercent );
                if (eResult != ProgressContinue)
                {
                    splash_destroy(splash);
                    splash = NULL;
                    bShortWait = sal_False;
                }

            }


            status = child_get_exit_code(info);
            g_pProcess = NULL; // reset
            switch (status) {
            case EXITHELPER_CRASH_WITH_RESTART: // re-start with just -env: parameters
                bRestart = sal_True;
                bAllArgs = sal_False;
                break;
            case EXITHELPER_NORMAL_RESTART: // re-start with all arguments
                bRestart = sal_True;
                bAllArgs = sal_True;
                break;
            default:
                break;
            }

            child_info_destroy (info);
        } while (bRestart);
    }

    /* cleanup */
    if ( pPipePath )
        rtl_uString_release( pPipePath );
    args_free (args);

    return status;
}
Exemplo n.º 8
0
std::string get_app_dir() {
    return fs::path(get_app_path()).parent_path().string();
}