Пример #1
0
char *set_my_path(HINSTANCE h, char *dest, const char *fname)
{
    dest[0] = 0;
    if (0 == is_absolute_path(fname))
        get_exe_path(h, dest, MAX_PATH);
    return strcat(dest, fname);
}
Пример #2
0
char *make_bb_path(HINSTANCE h, char *dest, const char *src)
{
    dest[0]=0;
    if (is_relative_path(src))
		get_exe_path(h, dest, sizeof dest);
    return strcat(dest, src);
}
Пример #3
0
int main(int argc, char **argv)
{
	/* Libtap call for the number of tests planned. */
	plan_tests(NUM_TESTS);

	gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
	OTRL_INIT;

	if (get_exe_path(curdir, sizeof(curdir)) < 0) {
		return -ENOMEM;
	}

	/* Build the full path of the instag.txt file. */
	(void) snprintf(instag_filepath, sizeof(instag_filepath), "%s%s",
			curdir, "instag.txt");

	test_otrl_instag_forget();
	test_otrl_instag_forget_all();
	test_otrl_instag_find();
	test_otrl_instag_read();
	test_otrl_instag_read_FILEp();
	test_otrl_instag_get_new();

	return 0;
}
Пример #4
0
void log_pidcalls (void)
{
	static unint	interval = 0;
	Pidcall_s	*pc;
	int		pid;
	int		i;
	int		rc;

	if (!Fp) return;
	++interval;
	for (i = 0; i < Num_rank; i++) {
		pc = Rank_pidcall[i];
		pid = get_pid(pc->pidcall);
		if (!pc->name) {
			pc->name = get_exe_path(pid);
		}
		rc = fprintf(Fp, "%ld,%d,%d,%lld,%s,%s\n",
			interval, pid, pc->snap.count,
			pc->snap.total_time,
			Syscall[get_call(pc->pidcall)],
			pc->name);
		if (rc < 0) {
			warn("Log failed %s:", File);
			log_close();
		}
	}
}
Пример #5
0
const char* get_base_resource_path()
{
    if(resource_path == NULL) {
        resource_path = calloc(512, sizeof(char));
        get_exe_path(resource_path, 512);
    }

    return resource_path;
}
Пример #6
0
int main()
{
	wxString pwd=::wxGetCwd();
	printf("#pwd %s \n", pwd.mb_str().data());

	wxString pwd2= get_exe_path();
	printf("#pwd %s \n", pwd2.mb_str().data());
	return 0;
}
Пример #7
0
const char *get_relative_path(HINSTANCE h, const char *path)
{
    char basedir[MAX_PATH];
    int l;
    get_exe_path(h, basedir, sizeof basedir);
    l = strlen(basedir);
    if (l && 0 == memicmp(path, basedir, l))
        return path + l;
    return path;
}
Пример #8
0
/*
 * Called when the user releases the mouse button. Checks whether the
 * coordinates are over a button and executes the appropriate action.
 *
 */
static void handle_button_release(xcb_connection_t *conn, xcb_button_release_event_t *event) {
    printf("button released on x = %d, y = %d\n",
           event->event_x, event->event_y);
    /* If the user hits the close button, we exit(0) */
    if (event->event_x >= (rect.width - logical_px(32)))
        exit(0);
    button_t *button = get_button_at(event->event_x, event->event_y);
    if (!button)
        return;

    /* We need to create a custom script containing our actual command
     * since not every terminal emulator which is contained in
     * i3-sensible-terminal supports -e with multiple arguments (and not
     * all of them support -e with one quoted argument either).
     *
     * NB: The paths need to be unique, that is, don’t assume users close
     * their nagbars at any point in time (and they still need to work).
     * */
    char *script_path = get_process_filename("nagbar-cmd");

    int fd = open(script_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
    if (fd == -1) {
        warn("Could not create temporary script to store the nagbar command");
        return;
    }
    FILE *script = fdopen(fd, "w");
    if (script == NULL) {
        warn("Could not fdopen() temporary script to store the nagbar command");
        return;
    }
    fprintf(script, "#!/bin/sh\nrm %s\n%s", script_path, button->action);
    /* Also closes fd */
    fclose(script);

    char *link_path;
    char *exe_path = get_exe_path(argv0);
    sasprintf(&link_path, "%s.nagbar_cmd", script_path);
    if (symlink(exe_path, link_path) == -1) {
        err(EXIT_FAILURE, "Failed to symlink %s to %s", link_path, exe_path);
    }

    char *terminal_cmd;
    sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", link_path);
    printf("argv0 = %s\n", argv0);
    printf("terminal_cmd = %s\n", terminal_cmd);

    start_application(terminal_cmd);

    free(link_path);
    free(terminal_cmd);
    free(script_path);
    free(exe_path);

    /* TODO: unset flag, re-render */
}
Пример #9
0
void set_resource_path_relative(const char* path)
{
    nulltest(path);
    if(resource_path != NULL)
        free(resource_path);

    resource_path = calloc(512 + strlen(path), sizeof(char));
    get_exe_path(resource_path, 512);
    strcat(resource_path, "/");
    strcat(resource_path, path);
}
Пример #10
0
void set_default_server_options(server_options& options){

    options.debug_flag = false;
    options.logging_enabled = false;
    options.file = "";
    options.port = 8080;
    options.dir = get_exe_path();
    options.time = 60;
    options.threadnum = 4;
    options.sched = "FCFS";
}
Пример #11
0
bool OEFind::get_conf_dir()
{
	char filename[1024];
	char dir[1024];

	get_exe_path(filename, 1024);
	get_file_dir(dir, filename, 1024);
	if (!get_absolute_path(conf_dir, "../conf/OEFind/", dir))
		return false;

	return true;
}
Пример #12
0
std::string get_config_path()
{
    //ex: C:\Users\Mark\Documents\Visual Studio
    //2010\Projects\FirstCPPApplication\Debug\BiochRL++.exe
    std::string exepath = get_exe_path();
    std::vector<std::string> exesplit = StringSplit(exepath, kPathSeparator);

    exesplit.pop_back();
    std::string data = "config";
    data+=kPathSeparator;
    exesplit.push_back(data);

    return StringJoin(exesplit, kPathSeparator, false);
};
Пример #13
0
void parse_args(char * argv[], int cnt){
  exec_path = get_exe_path();
  for(int i = 1; i < cnt; i++){
    char * arg = argv[i];
    bool is_test = strcmp(arg,"--test") == 0;
    if(is_test){
      run_test = true;
      continue;
    }
    bool compile_out = strcmp(arg,"--compile-out") == 0;
    if(compile_out){
      i++;
      c_compile_out = fmtstr("%s",argv[i]);
      continue;
    }
    file_to_run = argv[i];
  }
}
Пример #14
0
	wordbookmgr_impl() {
		
		auto path = get_exe_path();
		path += L"\\db";
		CreateDirectory(path.c_str(), nullptr);
		path += L"\\wordbook.db3";
		db_ = std::make_unique<Database>(utf8::w2a(path), SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); assert(db_);

		// init db
		{
			Statement query(*db_, "select name from sqlite_master where type='table'");
			if (!query.executeStep()) {
				// init
				db_->exec("create table wordbook (id integer primary key autoincrement, word text, date_add text)");
			}
		}
		
		//running_ = true;
		
	}
Пример #15
0
/*
 * get_exe_database_path() return current sqlite file path
 * /home/<user>/.config/<appname><id provided in the parameters>
 */
char *get_exe_database_path(const char *id) {
	char *home = getenv("HOME");
	char *config_path = "/.config/";
	char *dbname = ".db";
	char *exe_name = get_exe_path(0);
	char *full_database_path;
	int full_database_path_len = strlen(home) + strlen(config_path) + strlen(exe_name)  + strlen(id) +strlen(dbname)+ 1;
	
	full_database_path = (char*) malloc(full_database_path_len * sizeof(char));
	if (!full_database_path)
		return NULL;
		
	strcpy(full_database_path, home);
	strcat(full_database_path, config_path);
	strcat(full_database_path, exe_name);
	strcat(full_database_path, id);
	strcat(full_database_path, dbname);
	
	free(exe_name);
	return full_database_path;
}
Пример #16
0
int ssa_set_ssa_signal_handler()
{
	struct sigaction action;
	int ret;
#if 0
	/*
	 *  addr2line utility doesn't work with alternative stack
	 */
	stack_t our_stack;

	our_stack.ss_sp = (void *) malloc(SIGSTKSZ);
	our_stack.ss_size = SIGSTKSZ;
	our_stack.ss_flags = 0;

	if (sigaltstack(&our_stack, NULL) != 0)
		return 1;
#endif
	ret = pthread_spin_init(&signal_handler_lock, 0);
	if (ret)
		return ret;

	ret = get_exe_path();
	if (ret)
		return ret;

	action.sa_sigaction = ssa_signal_handler;
	sigemptyset(&action.sa_mask);

	action.sa_flags = SA_SIGINFO | SA_ONSTACK;

	if (sigaction(SIGSEGV, &action, NULL) != 0)
		return 1;
	if (sigaction(SIGFPE,  &action, NULL) != 0)
		return 1;
	if (sigaction(SIGILL,  &action, NULL) != 0)
		return 1;

	return 0;
}
Пример #17
0
int switch_to_game_directory()
{
    log_message("finding the game's directory");
    int size = 256;
    char *buffer = NULL;
    while(!buffer)
    {
        buffer = (char *)malloc(size);
        int ret = get_exe_path(buffer, size);

        // error
        if(ret <= 0)
        {
            free(buffer);
            buffer = NULL;
            log_message("failed locating the executable");
            return 0;
        }
        // buffer too small
        else if(ret == size)
        {
            free(buffer);
            buffer = NULL;
            size *= 2;
        }
    }

    char *dir = dirname(buffer);

    int success = chdir(dir);
    if(success == 0)
        log_messagef("changed directory to '%s'", dir);
    else
        log_messagef("failed to change directory to '%s'", dir);

    free(buffer);
    return success;
}
Пример #18
0
char* make_full_path(HINSTANCE h, char *buffer, const char *filename)
{
	buffer[0] = 0;
	if (NULL == strchr(filename, ':')) get_exe_path(h, buffer, sizeof buffer);
	return strcat(buffer, filename);
}
Пример #19
0
	bool start(const boost::filesystem::path &root) override
 	{
		if (running_) {
			if (root_ == root) {
				return true;
			} else {
				return false;
			}
		}

		SECURITY_ATTRIBUTES sa = {};

		sa.nLength = sizeof(sa);
		sa.bInheritHandle = TRUE;

		cancel_event_ = ::CreateEventW(&sa, TRUE, FALSE, nullptr);

		if (cancel_event_ == nullptr) {
			return false;
		}

		HANDLE hstdout_read = nullptr;
		HANDLE hstdout_write = nullptr;
		HANDLE hstderr_write = nullptr;

		if (::CreatePipe(&hstdout_read, &hstdout_write, &sa, 0) == FALSE) {
			return false;
		}

		if (::DuplicateHandle(
			::GetCurrentProcess(), hstdout_write, ::GetCurrentProcess(), &hstderr_write,
			0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
		{
			::CloseHandle(hstdout_read);
			::CloseHandle(hstdout_write);
			return false;
		}

		if (::DuplicateHandle(
			::GetCurrentProcess(), hstdout_read, ::GetCurrentProcess(), &hstdout_,
			0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
		{
			::CloseHandle(hstdout_read);
			::CloseHandle(hstdout_write);
			::CloseHandle(hstderr_write);
			return false;
		}

		STARTUPINFOW si = {};

		si.cb = sizeof(STARTUPINFOW);
		si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		si.hStdOutput = hstdout_write;
		si.hStdError = hstderr_write;
		si.wShowWindow = SW_HIDE;

		PROCESS_INFORMATION pi = {};

		std::wstring command = L'\"' + (get_exe_path().remove_filename() / L"console-helper.exe").wstring();

		command += L"\" ";
		command += std::to_wstring(reinterpret_cast<std::uintptr_t>(cancel_event_));
		command += L' ';
		command += L"jupyter notebook --no-browser ";
		command += L"--notebook-dir=\"";
		command += root.wstring();
		command += L'\"';

		auto result = ::CreateProcessW(
			nullptr,
			const_cast<LPWSTR>(command.c_str()),
			nullptr,
			nullptr,
			TRUE,
			CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP,
			nullptr,
			nullptr,
			&si,
			&pi);

		::CloseHandle(hstdout_read);
		::CloseHandle(hstdout_write);
		::CloseHandle(hstderr_write);

		if (result == FALSE) {
			::CloseHandle(hstdout_);
			return false;
		}

		running_ = true;
		helper_process_ = pi.hProcess;

		char buf_array[256];
		DWORD read;

		std::string buf;

		const char *text = "The Jupyter Notebook is running at: ";
		auto text_len = ::strlen(text);

		for (;;) {
			if (::ReadFile(hstdout_, (LPVOID)buf_array, 255, &read, nullptr) == FALSE) {
				return false;
			}

			buf_array[read] = '\0';
			buf += buf_array;

			auto pos = buf.find(text);

			if (pos != std::string::npos) {
				pos += text_len;

				auto pos_end = buf.find_first_of("\r\n", pos);

				if (pos_end != std::string::npos) {
					auto s = buf.substr(pos + 7, pos_end - pos - 7);
					pos = s.find(':');
					pos_end = s.find('/', pos);
					auto aa = s.substr(pos + 1, pos_end - pos - 1);
					if (pos != std::string::npos && pos_end != std::string::npos) {
						try {
							port_ = static_cast<unsigned short>(std::stoul(s.substr(pos + 1, pos_end - pos - 1)));
						} catch (std::exception &e) {
							stop();
							throw e;
						}
					}
					break;
				}
			}
		}

		return port_ != 0;
	}
Пример #20
0
int module_get_exe_path(char *buf, int len){
	return get_exe_path(buf, len, NULL);
}
Пример #21
0
BOOL CAlarmCenterApp::InitInstance()
{
	/*{
		bool connect_by_sse_or_ip_ = true;
		std::string cloud_sse_id_ = "";
		std::string device_ipv4_ = "";
		int device_port_ = 0;
		std::wstring user_name_ = L"";
		int user_id = 0;
		std::wstring _device_note = L"";
		int _id = 0;

		CString sql;
		sql.Format(L"update table_device_info_jovision set \
connect_by_sse_or_ip=%d,\
cloud_sse_id='%s',\
device_ipv4='%s',\
device_port=%d,\
user_name='%s',\
user_passwd='%s',\
user_info_id=%d,\
device_note='%s' where id=%d",
connect_by_sse_or_ip_ ? 1 : 0,
utf8::a2w(cloud_sse_id_).c_str(),
utf8::a2w(device_ipv4_).c_str(),
device_port_,
user_name_.c_str(),
user_id,
_device_note.c_str(),
_id);

		JLOG(sql);
	}*/


	do {
		if (IfProcessRunning())
			break;
		auto log = log::get_instance();
		log->set_output_to_dbg_view();
		log->set_line_prifix("HB");
		log->set_log_file_foler(get_exe_path_a() + "\\Log");
		log->set_log_file_prefix("AlarmCenter");
		log->set_output_to_file();
		
		JLOG(L"AlarmCenter startup.\n");
		AUTO_LOG_FUNCTION;

		int	nRet;
		WSAData	wsData;

		nRet = WSAStartup(MAKEWORD(2, 2), &wsData);
		if (nRet < 0) {
			JLOG(L"Can't load winsock.dll.\n");
			break;
		}


#pragma region init crashrpt
		// Place all significant initialization in InitInstance
		// Define CrashRpt configuration parameters
		CR_INSTALL_INFO info;
		memset(&info, 0, sizeof(CR_INSTALL_INFO));
		info.cb = sizeof(CR_INSTALL_INFO);
		info.pszAppName = _T("AlarmCenter");
		static CString version;
		detail::GetProductVersion(version);
		info.pszAppVersion = version;
		info.pszEmailSubject = _T("AlarmCenter Error Report");
		info.pszEmailTo = _T("*****@*****.**");
		info.pszUrl = _T("http://113.140.30.118/crashrpt.php");
		info.uPriorities[CR_HTTP] = 3;  // First try send report over HTTP 
		info.uPriorities[CR_SMTP] = 2;  // Second try send report over SMTP  
		info.uPriorities[CR_SMAPI] = 1; // Third try send report over Simple MAPI    
										// Install all available exception handlers
		info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS;
		// Restart the app on crash 
		info.dwFlags |= CR_INST_APP_RESTART;
		info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;
		//info.pszRestartCmdLine = _T("/restart");
		// Define the Privacy Policy URL 
		//info.pszPrivacyPolicyURL = _T("http://myapp.com/privacypolicy.html");

		// Install crash reporting
		int nResult = crInstall(&info);
		if (nResult != 0) {
			// Something goes wrong. Get error message.
			TCHAR szErrorMsg[512] = _T("");
			crGetLastErrorMsg(szErrorMsg, 512);
			_tprintf_s(_T("%s\n"), szErrorMsg);
			MessageBox(nullptr, szErrorMsg, L"Error", MB_ICONERROR);
			break;
		}

		// Set crash callback function
		//crSetCrashCallback(CrashCallback, nullptr);

		// Add our log file to the error report
		crAddFile2(utf8::a2w(log::get_instance()->get_log_file_path()).c_str(), nullptr, _T("Log File"), CR_AF_MAKE_FILE_COPY);

		// We want the screenshot of the entire desktop is to be added on crash
		crAddScreenshot2(CR_AS_VIRTUAL_SCREEN, 0);

		// Add a named property that means what graphics adapter is
		// installed on user's machine
		//crAddProperty(_T("VideoCard"), _T("nVidia GeForce 8600 GTS"));



#pragma endregion

		auto res = res::get_instance();
		auto cfg = util::CConfigHelper::get_instance();
		auto lang = cfg->get_language();
		auto path = get_exe_path();
#ifdef _DEBUG
		path = path.substr(0, path.find_last_of(L'\\'));
		path += L"\\installer";
#endif
		switch (lang) {	
		case util::AL_TAIWANESE:
			res->parse_file(path + L"\\lang\\zh-tw.txt");
			SetThreadUILanguage(MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), SORT_DEFAULT));
			break;
		case util::AL_ENGLISH:
			res->parse_file(path + L"\\lang\\en-us.txt");
			SetThreadUILanguage(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
			break;
		case util::AL_CHINESE:
		default:
			res->parse_file(path + L"\\lang\\zh-cn.txt");
			SetThreadUILanguage(MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_DEFAULT));
			break;
		}

		CAppResource::get_instance();

		// InitCommonControlsEx() is required on Windows XP if an application
		// manifest specifies use of ComCtl32.dll version 6 or later to enable
		// visual styles.  Otherwise, any window creation will fail.
		INITCOMMONCONTROLSEX InitCtrls;
		InitCtrls.dwSize = sizeof(InitCtrls);
		// Set this to include all the common control classes you want to use
		// in your application.
		InitCtrls.dwICC = ICC_WIN95_CLASSES;
		InitCommonControlsEx(&InitCtrls);

		CWinApp::InitInstance();

		AfxEnableControlContainer();

		// Create the shell manager, in case the dialog contains
		// any shell tree view or shell list view controls.
		auto pShellManager = std::make_unique<CShellManager>();

		// Activate "Windows Native" visual manager for enabling themes in MFC controls
		//CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

		// Standard initialization
		// If you are not using these features and wish to reduce the size
		// of your final executable, you should remove from the following
		// the specific initialization routines you do not need
		// Change the registry key under which our settings are stored
		// You should modify this string to be something appropriate
		// such as the name of your company or organization
		SetRegistryKey(_T("Local AppWizard-Generated Applications"));

		CLoginDlg loginDlg;
		if (loginDlg.DoModal() != IDOK) {
			JLOG(L"user canceled login.\n");
			break;
		}

		CSetupNetworkDlg setupDlg;
		if (setupDlg.DoModal() != IDOK) {
			JLOG(L"user canceled setup network.\n");
			break;
		}

		CAlarmCenterDlg dlg;
		m_pMainWnd = &dlg;
		INT_PTR nResponse = dlg.DoModal();
		if (nResponse == IDOK) {

		} else if (nResponse == IDCANCEL) {

		} else if (nResponse == -1) {
			TRACE(L"Warning: dialog creation failed, so application is terminating unexpectedly.\n");
			TRACE(L"Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
		}

		

	} while (false);

	
	//video::ezviz::sdk_mgr_ezviz::release_singleton();
	

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
Пример #22
0
int module_get_path(char *buf, int len, MODULE *mod){
	return get_exe_path(buf, len, mod->hLib);
}