Exemplo n.º 1
0
bool ViewWithAcrobat(WindowInfo *win, const WCHAR *args)
{
    if (!CanViewWithAcrobat(win))
        return false;

    ScopedMem<WCHAR> exePath(GetAcrobatPath());
    if (!exePath)
        return false;

    if (!args)
        args = L"";

    ScopedMem<WCHAR> params;
    // Command line format for version 6 and later:
    //   /A "page=%d&zoom=%.1f,%d,%d&..." <filename>
    // see http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf#page=5
    //   /P <filename>
    // see http://www.adobe.com/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf#page=24
    // TODO: Also set zoom factor and scroll to current position?
    if (win->IsDocLoaded() && HIWORD(GetFileVersion(exePath)) >= 6)
        params.Set(str::Format(L"/A \"page=%d\" %s \"%s\"", win->ctrl->CurrentPageNo(), args, win->ctrl->FilePath()));
    else
        params.Set(str::Format(L"%s \"%s\"", args, win->loadedFilePath));

    return LaunchFile(exePath, params);
}
Exemplo n.º 2
0
BOOL CSerial::init(){
	char com[10] = {};
	GetPrivateProfileString("Section","COM","-1",com,10,exePath() + "set.ini");
	BOOL Result = OpenSerialPort(com,9600,8,1); //打开串口后,自动接收数据 "COM3:"
	if(Result == 0) return 0;
	return 1;
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        boost::filesystem::path exePath(argv[0]);
        std::cout << "usage: " << exePath.filename().string() << " <RTSP url of stream>" << std::endl;
        return -1;
    }
    
    boost::program_options::options_description desc("");
	desc.add_options()
		("no-display", "")
		("url", boost::program_options::value<std::string>(), "url")
		("interface", boost::program_options::value<std::string>(), "interface")
		("buffer-size", boost::program_options::value<unsigned long>(), "buffer-size");
    
    boost::program_options::positional_options_description p;
    p.add("url", -1);
    
    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
              options(desc).positional(p).run(), vm);
    boost::program_options::notify(vm);
    
    const char* interfaceAddress;
    if (vm.count("interface"))
    {
		interfaceAddress = vm["interface"].as<std::string>().c_str();
    }
    else
    {
		interfaceAddress = "0.0.0.0";
    }

	unsigned long bufferSize;
	if (vm.count("buffer-size"))
	{
		bufferSize = vm["buffer-size"].as<unsigned long>();
	}
	else
	{
		bufferSize = DEFAULT_SINK_BUFFER_SIZE;
	}

	std::cout << "Buffer size " << to_human_readable_byte_count(bufferSize, false, false) << std::endl;

	rtspClient = RTSPCubemapSourceClient::create(vm["url"].as<std::string>().c_str(), bufferSize, AV_PIX_FMT_RGBA, false, interfaceAddress);
    std::function<void (RTSPCubemapSourceClient*, CubemapSource*)> callback(boost::bind(&onDidConnect, _1, _2));
    rtspClient->setOnDidConnect(callback);
    rtspClient->connect();
    
    barrier.wait();
    
    Renderer renderer(cubemapSource);
	renderer.setOnDisplayedCubemapFace(boost::bind(&onDisplayedCubemapFace, _1, _2));
	renderer.setOnDisplayedFrame(boost::bind(&onDisplayedFrame, _1));
    renderer.start(); // Returns when window is closed
    
    CubemapSource::destroy(cubemapSource);
}
Exemplo n.º 4
0
std::string GetAppPath(std::string extra)
{
	ERROR_OUTPUT(__func__);
	char result[PATH_MAX] = {0};
	ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);

	if (count <= 0)
	{
		ERROR_OUTPUT("Could not read /proc/self/exe!");
		return "";
	}
	
	std::string exePath(result);

	// Cut off the filename.
	for(size_t i = count - 1; i > 0; i--)
	{
		if(result[i] == '/')
		{
			result[i] = '\0';
			break;
		}
	}

	return result;
}
Exemplo n.º 5
0
/* Caller needs to free() the result. */
WCHAR *AppGenDataFilename(WCHAR *fileName)
{
    ScopedMem<WCHAR> path;
    if (IsRunningInPortableMode()) {
        /* Use the same path as the binary */
        ScopedMem<WCHAR> exePath(GetExePath());
        if (exePath)
            path.Set(path::GetDir(exePath));
    } else {
        /* Use %APPDATA% */
        WCHAR dir[MAX_PATH];
        dir[0] = '\0';
        BOOL ok = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, TRUE);
        if (ok) {
            path.Set(path::Join(dir, APP_NAME_STR));
            if (path && !dir::Create(path))
                path.Set(NULL);
        }
    }

    if (!path || !fileName)
        return NULL;

    return path::Join(path, fileName);
}
Exemplo n.º 6
0
/* Return false if this program has been started from "Program Files" directory
   (which is an indicator that it has been installed) or from the last known
   location of a SumatraPDF installation: */
bool IsRunningInPortableMode()
{
    // cache the result so that it will be consistent during the lifetime of the process
    static int sCacheIsPortable = -1; // -1 == uninitialized, 0 == installed, 1 == portable
    if (sCacheIsPortable != -1)
        return sCacheIsPortable != 0;
    sCacheIsPortable = 1;

    if (HasBeenInstalled()) {
        sCacheIsPortable = 0;
        return false;
    }

    ScopedMem<WCHAR> exePath(GetExePath());
    ScopedMem<WCHAR> programFilesDir(GetSpecialFolder(CSIDL_PROGRAM_FILES));
    // if we can't get a path, assume we're not running from "Program Files"
    if (!exePath || !programFilesDir)
        return true;

    // check if one of the exePath's parent directories is "Program Files"
    // (or a junction to it)
    WCHAR *baseName;
    while ((baseName = (WCHAR*)path::GetBaseName(exePath)) > exePath) {
        baseName[-1] = '\0';
        if (path::IsSame(programFilesDir, exePath)) {
            sCacheIsPortable = 0;
            return false;
        }
    }

    return true;
}
Exemplo n.º 7
0
static WCHAR *GetXPSViewerPath()
{
    // the XPS-Viewer seems to always be installed into %WINDIR%\system32
    WCHAR buffer[MAX_PATH];
    UINT res = GetSystemDirectory(buffer, dimof(buffer));
    if (!res || res >= dimof(buffer))
        return NULL;
    ScopedMem<WCHAR> exePath(path::Join(buffer, L"xpsrchvw.exe"));
    if (file::Exists(exePath))
        return exePath.StealData();
#ifndef _WIN64
    // Wow64 redirects access to system32 to syswow64 instead, so we
    // disable file system redirection using the recommended method from
    // http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx
    if (IsRunningInWow64()) {
        res = GetWindowsDirectory(buffer, dimof(buffer));
        if (!res || res >= dimof(buffer))
            return NULL;
        exePath.Set(path::Join(buffer, L"Sysnative\\xpsrchvw.exe"));
        if (file::Exists(exePath))
            return exePath.StealData();
    }
#endif
    return NULL;
}
Exemplo n.º 8
0
void CT_StartAppTestStep::TestStartApp9L()
	{
	INFO_PRINTF1(_L("Test to check the StartApp API with forced memory failures..."));
	CApaCommandLine* cmdLn=CApaCommandLine::NewLC();
	TFileName filename;
	TThreadId threadId(0);
	TInt fail;
	_LIT(KLitExePath,"\\sys\\bin\\texe.exe");
	TFullName exePath(KLitExePath);
	filename = SearchAndReturnCompleteFileName(exePath);	
	cmdLn->SetExecutableNameL(filename);
	TInt ret = KErrNoMemory;
	//Without the fix for the Incident INC104463, the OOM test causes panic 
	//KERN-EXEC 56.	
	for(fail=1; ret == KErrNoMemory; fail++)
		{	
		__UHEAP_SETFAIL(RHeap::EDeterministic, fail);
		__UHEAP_MARK;
		ret = iApaLsSession.StartApp(*cmdLn, threadId);
		__UHEAP_MARKEND;
		__UHEAP_RESET;
		TEST((ret==KErrNoMemory || ret==KErrNone));
		if(ret == KErrNone)
			{
			TEST(threadId.Id() != 0);
			}
		}	
	INFO_PRINTF3(_L("Iteration count is %d and the value of return is %d "),fail-1 ,ret);
	CleanupStack::PopAndDestroy(cmdLn); 
	INFO_PRINTF1(KCompleted);
	}
Exemplo n.º 9
0
void GLDMaskWidget::init()
{
    m_gldGuideInfoList.clear();
    parseXMl(exePath() + XMLPath);
    m_Step = 0;
    setCurrentGuidePage();
}
Exemplo n.º 10
0
void GLDMaskWidget::closeMaskWidget()
{
    QSettings oInis(exePath() + "/config/NewGuide.ini", QSettings::IniFormat);
    oInis.setValue("GLDMaskWidget", 1);

    close();
}
Exemplo n.º 11
0
// cf. http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx
static bool WriteExtendedFileExtensionInfo(HKEY hkey)
{
    bool success = true;

    ScopedMem<WCHAR> exePath(GetInstalledExePath());
    if (HKEY_LOCAL_MACHINE == hkey)
        success &= WriteRegStr(hkey, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" EXENAME, NULL, exePath);

    // mirroring some of what DoAssociateExeWithPdfExtension() does (cf. AppTools.cpp)
    ScopedMem<WCHAR> iconPath(str::Join(exePath, L",1"));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\DefaultIcon", NULL, iconPath);
    ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Open\\Command", NULL, cmdPath);
    ScopedMem<WCHAR> printPath(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Print\\Command", NULL, printPath);
    ScopedMem<WCHAR> printToPath(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\PrintTo\\Command", NULL, printToPath);
    // don't add REG_CLASSES_APPS L"\\SupportedTypes", as that prevents SumatraPDF.exe to
    // potentially appear in the Open With lists for other filetypes (such as single images)

    // add the installed SumatraPDF.exe to the Open With lists of the supported file extensions
    for (int i = 0; NULL != gSupportedExts[i]; i++) {
        ScopedMem<WCHAR> keyname(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" EXENAME));
        success &= CreateRegKey(hkey, keyname);
        // TODO: stop removing this after version 1.8 (was wrongly created for version 1.6)
        keyname.Set(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" APP_NAME_STR));
        DeleteRegKey(hkey, keyname);
    }

    // in case these values don't exist yet (we won't delete these at uninstallation)
    success &= WriteRegStr(hkey, REG_CLASSES_PDF, L"Content Type", L"application/pdf");
    success &= WriteRegStr(hkey, L"Software\\Classes\\MIME\\Database\\Content Type\\application/pdf", L"Extension", L".pdf");

    return success;
}
Exemplo n.º 12
0
bool CanViewWithAcrobat(WindowInfo *win)
{
    // Requirements: a valid filename and a valid path to Adobe Reader
    if (win && !CouldBePDFDoc(win) || !CanViewExternally(win))
        return false;
    ScopedMem<WCHAR> exePath(GetAcrobatPath());
    return exePath != NULL;
}
Exemplo n.º 13
0
static bool TryLoadMemTrace()
{
    ScopedMem<TCHAR> exePath(GetExePath());
    ScopedMem<TCHAR> exeDir(path::GetDir(exePath));
    ScopedMem<TCHAR> dllPath(path::Join(exeDir, _T("memtrace.dll")));
    if (!LoadLibrary(dllPath))
        return false;
    return true;
}
Exemplo n.º 14
0
static WCHAR *GetPDFXChangePath()
{
    ScopedMem<WCHAR> path(ReadRegStr(HKEY_LOCAL_MACHINE, L"Software\\Tracker Software\\PDFViewer", L"InstallPath"));
    if (!path)
        path.Set(ReadRegStr(HKEY_CURRENT_USER, L"Software\\Tracker Software\\PDFViewer", L"InstallPath"));
    if (!path)
        return NULL;
    ScopedMem<WCHAR> exePath(path::Join(path, L"PDFXCview.exe"));
    if (file::Exists(exePath))
        return exePath.StealData();
    return NULL;
}
Exemplo n.º 15
0
    /**
     * Get the path string to be used when searching for PDB files.
     * 
     * @param process        Process handle
     * @return searchPath    Returned search path string
     */
    static const char* getSymbolSearchPath(HANDLE process) {
        static std::string symbolSearchPath;

        if (symbolSearchPath.empty()) {
            static const size_t bufferSize = 1024;
            boost::scoped_array<char> pathBuffer(new char[bufferSize]);
            GetModuleFileNameA(NULL, pathBuffer.get(), bufferSize);
            boost::filesystem::path exePath(pathBuffer.get());
            symbolSearchPath = exePath.parent_path().string();
            symbolSearchPath += ";C:\\Windows\\System32;C:\\Windows";
        }
        return symbolSearchPath.c_str();
    }
Exemplo n.º 16
0
void PipedProcess::Terminate()
{
#ifdef __WXGTK__
	wxString cmd;
	wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
	wxFileName script(exePath.GetPath(), wxT("codelite_kill_children"));
	cmd << wxT("/bin/sh -f ") << script.GetFullPath() << wxT(" ") << GetPid();
	wxExecute(cmd, wxEXEC_ASYNC);
#else
	wxKillError rc;
	wxKill(GetPid(), wxSIGKILL, &rc, wxKILL_CHILDREN);
#endif
}
Exemplo n.º 17
0
static void HtmlParserFile()
{
    TCHAR *fileName = _T("HtmlParseTest00.html");
    // We assume we're being run from obj-[dbg|rel], so the test
    // files are in ..\src\utils directory relative to exe's dir
    ScopedMem<TCHAR> exePath(GetExePath());
    const TCHAR *exeDir = path::GetBaseName(exePath);
    ScopedMem<TCHAR> p1(path::Join(exeDir, _T("..\\src\\utils")));
    ScopedMem<TCHAR> p2(path::Join(p1, fileName));
    char *d = file::ReadAll(p2, NULL);
    // it's ok if we fail - we assume we were not run from the
    // right location
    if (!d)
        return;
    HtmlParser p;
    HtmlElement *root = p.ParseInPlace(d);
    assert(root);
    assert(709 == p.ElementsCount());
    assert(955 == p.TotalAttrCount());
    assert(str::Eq(root->name, "html"));
    HtmlElement *el = root->down;
    assert(str::Eq(el->name, "head"));
    el = el->next;
    assert(str::Eq(el->name, "body"));
    el = el->down;
    assert(str::Eq(el->name, "object"));
    el = el->next;
    assert(str::Eq(el->name, "ul"));
    el = el->down;
    assert(str::Eq(el->name, "li"));
    el = el->down;
    assert(str::Eq(el->name, "object"));
    ScopedMem<TCHAR> val(el->GetAttribute("type"));
    assert(str::Eq(val, _T("text/sitemap")));
    el = el->down;
    assert(str::Eq(el->name, "param"));
    assert(!el->down);
    assert(str::Eq(el->next->name, "param"));
    el = p.FindElementByName("body");
    assert(el);
    el = p.FindElementByName("ul", el);
    assert(el);
    int count = 0;
    while (el) {
        ++count;
        el = p.FindElementByName("ul", el);
    }
    assert(18 == count);
    free(d);
}
Exemplo n.º 18
0
static HWND FindPrevInstWindow(HANDLE *hMutex)
{
    // create a unique identifier for this executable
    // (allows independent side-by-side installations)
    ScopedMem<WCHAR> exePath(GetExePath());
    str::ToLower(exePath);
    uint32_t hash = MurmurHash2(exePath.Get(), str::Len(exePath) * sizeof(WCHAR));
    ScopedMem<WCHAR> mapId(str::Format(L"SumatraPDF-%08x", hash));

    int retriesLeft = 3;
Retry:
    // use a memory mapping containing a process id as mutex
    HANDLE hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(DWORD), mapId);
    if (!hMap)
        goto Error;
    bool hasPrevInst = GetLastError() == ERROR_ALREADY_EXISTS;
    DWORD *procId = (DWORD *)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD));
    if (!procId) {
        CloseHandle(hMap);
        goto Error;
    }
    if (!hasPrevInst) {
        *procId = GetCurrentProcessId();
        UnmapViewOfFile(procId);
        *hMutex = hMap;
        return NULL;
    }

    // if the mapping already exists, find one window belonging to the original process
    DWORD prevProcId = *procId;
    UnmapViewOfFile(procId);
    CloseHandle(hMap);
    HWND hwnd = NULL;
    while ((hwnd = FindWindowEx(HWND_DESKTOP, hwnd, FRAME_CLASS_NAME, NULL)) != NULL) {
        DWORD wndProcId;
        GetWindowThreadProcessId(hwnd, &wndProcId);
        if (wndProcId == prevProcId) {
            AllowSetForegroundWindow(prevProcId);
            return hwnd;
        }
    }

    // fall through
Error:
    if (--retriesLeft < 0)
        return NULL;
    Sleep(100);
    goto Retry;
}
Exemplo n.º 19
0
/**
   @SYMTestCaseID APPFWK-APPARC-0071
 
   @SYMDEF PDEF100072 -- CApaWindowGroupName::SetAppUid() and FindByAppUid panic
 
   @SYMTestCaseDesc Test Launching of an application with unprotected application UID
  
   @SYMTestPriority High 
 
   @SYMTestStatus Implemented
  
   @SYMTestActions Prepare command line information to start an application using
   CApaCommandLine Apis.Call RApaLsSession::StartApp() to start an
   application defined by the command line information.\n
   Test the launching of application for following scenario:\n
   When Application specified by command line has unprotected application UID(negative uid).\n
   API Calls:\n	
   RApaLsSession::StartApp(const CApaCommandLine &aCommandLine, TThreadId &aThreadId);\n
  
   @SYMTestExpectedResults The test checks whether the thread has terminated with the exit reason KTUnProtectedAppTestPassed
 */
void CT_StartAppTestStep::TestStartApp8L()
	{
	INFO_PRINTF1(_L("Checking launching of an application which has unprotected UID"));
	CApaCommandLine* cmdLine=CApaCommandLine::NewLC();
	TFileName filename;
	_LIT(KAppFileName, "z:\\sys\\bin\\UnProctectedUidApp.exe");
	TFullName exePath(KAppFileName);
	filename = SearchAndReturnCompleteFileName(exePath);
	cmdLine->SetExecutableNameL(filename);
	
	TThreadId appThreadId(0U);
	TInt ret = iApaLsSession.StartApp(*cmdLine, appThreadId);
	TEST(ret == KErrNone);
	User::LeaveIfError(ret);
	CleanupStack::PopAndDestroy(cmdLine); // cmdLine
	
	RThread appThread;
	User::LeaveIfError(appThread.Open(appThreadId));
	
	TRequestStatus logonRequestStatus;
	appThread.Logon(logonRequestStatus);

	// wait for UnProctectedUidApp.exe to terminate
	INFO_PRINTF1(_L("Waiting for application to terminate..."));
	User::WaitForRequest(logonRequestStatus);

	const TExitType exitType = appThread.ExitType();
	const TInt exitReason = appThread.ExitReason();
	TExitCategoryName categoryName = appThread.ExitCategory();
	appThread.Close();

	TBuf<50> msg;
	if (exitType == EExitPanic)
		{
		_LIT(KAppPanicInfo, "Application panic: %S %d");
		msg.Format(KAppPanicInfo, &categoryName, exitReason);
		}
	else
		{
		_LIT(KAppExitInfo, "Application exited with code %d");
		msg.Format(KAppExitInfo, exitReason);
		}
	INFO_PRINTF1(msg);

	TEST(logonRequestStatus == KTUnProtectedAppTestPassed);
	TEST(exitType == EExitKill);
	TEST(exitReason == KTUnProtectedAppTestPassed);
	INFO_PRINTF1(KCompleted);
	}
Exemplo n.º 20
0
TEST_F(FS, setResourceRoot) {

	// Set properly.
	EXPECT_EQ(
		resourceRoot().string(),
		(exePath() / "resource" / "FS" / "setResourceRoot").string()
	);

	// Non-existent root.
	EXPECT_THROW(
		setResourceRoot("/this/will/throw"),
		boost::filesystem::filesystem_error
	);

}
Exemplo n.º 21
0
/* Returns true, if a Registry entry indicates that this executable has been
   created by an installer (and should be updated through an installer) */
bool HasBeenInstalled()
{
    ScopedMem<WCHAR> installedPath;
    // cf. GetInstallationDir() in installer\Installer.cpp
    installedPath.Set(ReadRegStr(HKEY_CURRENT_USER, REG_PATH_UNINST, L"InstallLocation"));
    if (!installedPath)
        installedPath.Set(ReadRegStr(HKEY_LOCAL_MACHINE, REG_PATH_UNINST, L"InstallLocation"));
    if (!installedPath)
        return false;

    ScopedMem<WCHAR> exePath(GetExePath());
    if (!exePath)
        return false;

    if (!str::EndsWithI(installedPath, L".exe"))
        installedPath.Set(path::Join(installedPath, path::GetBaseName(exePath)));
    return path::IsSame(installedPath, exePath);
}
Exemplo n.º 22
0
wxString CfgMgrBldr::FindConfigFile(const wxString& filename)
{

    wxString u(ConfigManager::GetUserDataFolder() + wxFILE_SEP_PATH + filename);
    wxString exePath(::DetermineExecutablePath());
    wxString e(exePath + wxFILE_SEP_PATH + filename);

    if (!ConfigManager::has_alternate_user_data_path && ::wxFileExists(e))
    {
        ConfigManager::SetUserDataFolder(exePath);
        return e;
    }
    if (::wxFileExists(u))
    {
        return u;
    }
    return wxEmptyString;
}
Exemplo n.º 23
0
static WCHAR *GetHtmlHelpPath()
{
    // the Html Help viewer seems to be installed either into %WINDIR% or %WINDIR%\system32
    WCHAR buffer[MAX_PATH];
    UINT res = GetWindowsDirectory(buffer, dimof(buffer));
    if (!res || res >= dimof(buffer))
        return NULL;
    ScopedMem<WCHAR> exePath(path::Join(buffer, L"hh.exe"));
    if (file::Exists(exePath))
        return exePath.StealData();
    res = GetSystemDirectory(buffer, dimof(buffer));
    if (!res || res >= dimof(buffer))
        return NULL;
    exePath.Set(path::Join(buffer, L"hh.exe"));
    if (file::Exists(exePath))
        return exePath.StealData();
    return NULL;
}
Exemplo n.º 24
0
/* Return false if this program has been started from "Program Files" directory
   (which is an indicator that it has been installed) or from the last known
   location of a SumatraPDF installation (HKLM\Software\SumatraPDF\Install_Dir) */
bool IsRunningInPortableMode()
{
    // cache the result so that it will be consistent during the lifetime of the process
    static int sCacheIsPortable = -1; // -1 == uninitialized, 0 == installed, 1 == portable
    if (sCacheIsPortable != -1)
        return sCacheIsPortable != 0;
    sCacheIsPortable = 1;

    ScopedMem<WCHAR> exePath(GetExePath());
    if (!exePath)
        return true;

    // if we can't get a path, assume we're not running from "Program Files"
    ScopedMem<WCHAR> installedPath(NULL);
    installedPath.Set(ReadRegStr(HKEY_LOCAL_MACHINE, L"Software\\" APP_NAME_STR, L"Install_Dir"));
    if (!installedPath)
        installedPath.Set(ReadRegStr(HKEY_CURRENT_USER, L"Software\\" APP_NAME_STR, L"Install_Dir"));
    if (installedPath) {
        if (!str::EndsWithI(installedPath.Get(), L".exe"))
            installedPath.Set(path::Join(installedPath.Get(), path::GetBaseName(exePath)));
        if (path::IsSame(installedPath, exePath)) {
            sCacheIsPortable = 0;
            return false;
        }
    }

    WCHAR programFilesDir[MAX_PATH] = { 0 };
    BOOL ok = SHGetSpecialFolderPath(NULL, programFilesDir, CSIDL_PROGRAM_FILES, FALSE);
    if (!ok)
        return true;

    // check if one of the exePath's parent directories is "Program Files"
    // (or a junction to it)
    WCHAR *baseName;
    while ((baseName = (WCHAR*)path::GetBaseName(exePath)) > exePath) {
        baseName[-1] = '\0';
        if (path::IsSame(programFilesDir, exePath)) {
            sCacheIsPortable = 0;
            return false;
        }
    }

    return true;
}
Exemplo n.º 25
0
void DoAssociateExeWithPdfExtension(HKEY hkey)
{
    ScopedMem<WCHAR> exePath(GetExePath());
    if (!exePath)
        return;

    ScopedMem<WCHAR> prevHandler(nullptr);
    // Remember the previous default app for the Uninstaller
    prevHandler.Set(ReadRegStr(hkey, REG_CLASSES_PDF, nullptr));
    if (prevHandler && !str::Eq(prevHandler, APP_NAME_STR))
        WriteRegStr(hkey, REG_CLASSES_APP, L"previous.pdf", prevHandler);

    WriteRegStr(hkey, REG_CLASSES_APP, nullptr, _TR("PDF Document"));
    WCHAR *icon_path = str::Join(exePath, L",1");
    WriteRegStr(hkey, REG_CLASSES_APP L"\\DefaultIcon", nullptr, icon_path);
    free(icon_path);

    WriteRegStr(hkey, REG_CLASSES_APP L"\\shell", nullptr, L"open");

    ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath.Get())); // "${exePath}" "%1" %*
    bool ok = WriteRegStr(hkey, REG_CLASSES_APP L"\\shell\\open\\command", nullptr, cmdPath);

    // also register for printing
    cmdPath.Set(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath.Get())); // "${exePath}" -print-to-default "%1"
    WriteRegStr(hkey, REG_CLASSES_APP L"\\shell\\print\\command", nullptr, cmdPath);

    // also register for printing to specific printer
    cmdPath.Set(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath.Get())); // "${exePath}" -print-to "%2" "%1"
    WriteRegStr(hkey, REG_CLASSES_APP L"\\shell\\printto\\command", nullptr, cmdPath);

    // Only change the association if we're confident, that we've registered ourselves well enough
    if (!ok)
        return;

    WriteRegStr(hkey, REG_CLASSES_PDF, nullptr, APP_NAME_STR);
    // TODO: also add SumatraPDF to the Open With lists for the other supported extensions?
    WriteRegStr(hkey, REG_CLASSES_PDF L"\\OpenWithProgids", APP_NAME_STR, L"");
    if (hkey == HKEY_CURRENT_USER) {
        WriteRegStr(hkey, REG_EXPLORER_PDF_EXT, L"Progid", APP_NAME_STR);
        CrashIf(hkey == 0); // to appease prefast
        SHDeleteValue(hkey, REG_EXPLORER_PDF_EXT, L"Application");
        DeleteRegKey(hkey, REG_EXPLORER_PDF_EXT L"\\UserChoice", true);
    }
}
Exemplo n.º 26
0
bool IsRunningInPortableMode()
{
    // cache the result so that it will be consistent during the lifetime of the process
    static int sCacheIsPortable = -1; // -1 == uninitialized, 0 == installed, 1 == portable
    if (sCacheIsPortable != -1)
        return sCacheIsPortable != 0;
    sCacheIsPortable = 1;

    ScopedMem<WCHAR> exePath(GetExePath());
    if (!exePath)
        return true;

    // if we can't get a path, assume we're not running from "Program Files"
    ScopedMem<WCHAR> installedPath;
    // cf. GetInstallationDir() in installer\Installer.cpp
    installedPath.Set(ReadRegStr(HKEY_CURRENT_USER, REG_PATH_UNINST, L"InstallLocation"));
    if (!installedPath)
        installedPath.Set(ReadRegStr(HKEY_LOCAL_MACHINE, REG_PATH_UNINST, L"InstallLocation"));
    if (installedPath) {
        if (!str::EndsWithI(installedPath.Get(), L".exe"))
            installedPath.Set(path::Join(installedPath.Get(), path::GetBaseName(exePath)));
        if (path::IsSame(installedPath, exePath)) {
            sCacheIsPortable = 0;
            return false;
        }
    }

    ScopedMem<WCHAR> programFilesDir(GetSpecialFolder(CSIDL_PROGRAM_FILES));
    if (!programFilesDir)
        return true;

    // check if one of the exePath's parent directories is "Program Files"
    // (or a junction to it)
    WCHAR *baseName;
    while ((baseName = (WCHAR*)path::GetBaseName(exePath)) > exePath) {
        baseName[-1] = '\0';
        if (path::IsSame(programFilesDir, exePath)) {
            sCacheIsPortable = 0;
            return false;
        }
    }

    return true;
}
Exemplo n.º 27
0
// cf. http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx
static bool WriteExtendedFileExtensionInfo(HKEY hkey)
{
    bool ok = true;

    ScopedMem<WCHAR> exePath(GetInstalledExePath());
    if (HKEY_LOCAL_MACHINE == hkey)
        ok &= WriteRegStr(hkey, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" EXENAME, nullptr, exePath);

    // mirroring some of what DoAssociateExeWithPdfExtension() does (cf. AppTools.cpp)
    ScopedMem<WCHAR> iconPath(str::Join(exePath, L",1"));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\DefaultIcon", nullptr, iconPath);
    ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Open\\Command", nullptr, cmdPath);
    ScopedMem<WCHAR> printPath(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Print\\Command", nullptr, printPath);
    ScopedMem<WCHAR> printToPath(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\PrintTo\\Command", nullptr, printToPath);
    // don't add REG_CLASSES_APPS L"\\SupportedTypes", as that prevents SumatraPDF.exe to
    // potentially appear in the Open With lists for other filetypes (such as single images)

    // add the installed SumatraPDF.exe to the Open With lists of the supported file extensions
    // TODO: per http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx we shouldn't be
    // using OpenWithList but OpenWithProgIds. Also, it doesn't seem to work on my win7 32bit
    // (HKLM\Software\Classes\.mobi\OpenWithList\SumatraPDF.exe key is present but "Open With"
    // menu item doesn't even exist for .mobi files
    // It's not so easy, though, because if we just set it to SumatraPDF,
    // all gSupportedExts will be reported as "PDF Document" by Explorer, so this needs
    // to be more intelligent. We should probably mimic Windows Media Player scheme i.e.
    // set OpenWithProgIds to SumatraPDF.AssocFile.Mobi etc. and create apropriate
    // \SOFTWARE\Classes\CLSID\{GUID}\ProgID etc. entries
    // Also, if Sumatra is the only program handling those docs, our
    // PDF icon will be shown (we need icons and properly configure them)
    for (int i = 0; nullptr != gSupportedExts[i]; i++) {
        ScopedMem<WCHAR> keyname(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" EXENAME));
        ok &= CreateRegKey(hkey, keyname);
    }

    // in case these values don't exist yet (we won't delete these at uninstallation)
    ok &= WriteRegStr(hkey, REG_CLASSES_PDF, L"Content Type", L"application/pdf");
    ok &= WriteRegStr(hkey, L"Software\\Classes\\MIME\\Database\\Content Type\\application/pdf", L"Extension", L".pdf");

    return ok;
}
Exemplo n.º 28
0
wxString FileNames::HtmlHelpDir()
{
#if defined(__WXMAC__)
   wxFileName exePath(PlatformCompatibility::GetExecutablePath());
      // This removes (for instance) "Audacity.app/Contents/MacOSX"
      exePath.RemoveLastDir();
      exePath.RemoveLastDir();
      exePath.RemoveLastDir();
   
   return wxFileName( exePath.GetPath()+wxT("/help/manual"), wxEmptyString ).GetFullPath();
#else
   //linux goes into /*prefix*/share/audacity/
   //windows goes into the dir containing the .exe
   wxString exeDir = wxStandardPaths::Get().GetDataDir();
   
   //for mac this puts us within the .app: Audacity.app/Contents/SharedSupport/
   return wxFileName( exeDir+wxT("/help/manual"), wxEmptyString ).GetFullPath();
#endif   
}
Exemplo n.º 29
0
bool ViewWithHtmlHelp(WindowInfo *win, const WCHAR *args)
{
    if (!CanViewWithHtmlHelp(win))
        return false;

    ScopedMem<WCHAR> exePath(GetHtmlHelpPath());
    if (!exePath)
        return false;

    if (!args)
        args = L"";

    ScopedMem<WCHAR> params;
    if (win->IsDocLoaded())
        params.Set(str::Format(L"%s \"%s\"", args, win->ctrl->FilePath()));
    else
        params.Set(str::Format(L"%s \"%s\"", args, win->loadedFilePath));
    return LaunchFile(exePath, params);
}
Exemplo n.º 30
0
IrregularForm::IrregularForm(QWidget *parent)
    : QWidget(parent)
{
    //ÉèÖô°ÌåÎޱ߿ò
    setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_NoSystemBackground);
    setAttribute(Qt::WA_TranslucentBackground);


    //setAutoFillBackground(true);
    //QPalette palette;
    //palette.setColor(QPalette::Background, QColor(192, 253, 123));
    //setPalette(palette);

    //¼ÓÔØͼÏñ
    pic.load(exePath() + "/images/Msg/change_skin_text.png");

    resize(pic.size());
}