Ejemplo n.º 1
0
/* return 0 on success.
 * return -1 if could not write file.
 * return -2 if download failed.
 */
static int download_and_install_new_utox_version()
{
    FILE *file;
    void *new_version_data;
    uint32_t len, rlen;
    new_version_data = download_loop_all_host_ips(1, TOX_DOWNNLOAD_HOSTS, NUMBER_UPDATE_HOSTS, GET_NAME, strlen(GET_NAME), &len, 1024 * 1024 * 4, TOX_SELF_PUBLICK_KEY, TOX_VERSION_NAME, APPENDED_VERSION_LENGTH);

    if (!new_version_data) {
        LOG_TO_FILE("download failed\n");
        if (is_tox_installed) {
            open_utox_and_exit();
        }

        return -2;
    }

    LOG_TO_FILE("Inflated size: %u\n", len);

    /* delete old version if found */
    file = fopen(TOX_VERSION_FILENAME, "rb");
    if (file) {
        char old_name[32];
        rlen = fread(old_name, 1, sizeof(old_name) - 1, file);
        old_name[rlen] = 0;

        /* Only there for smooth update from old updater. */
        DeleteFile(old_name);
        fclose(file);
    }

    /* write file */
    file = fopen(TOX_EXE_NAME, "wb");
    if (!file) {
        LOG_TO_FILE("fopen failed\n");
        free(new_version_data);
        return -1;
    }

    rlen = fwrite(new_version_data, 1, len, file);
    fclose(file);
    free(new_version_data);
    if (rlen != len) {
        LOG_TO_FILE("write failed (%u)\n", rlen);
        return -1;
    }

    /* write version to file */
    file = fopen(TOX_VERSION_FILENAME, "wb");
    if (file) {
        rlen = fwrite(TOX_VERSION_NAME, 1, APPENDED_VERSION_LENGTH, file);
        fclose(file);
        if (rlen != APPENDED_VERSION_LENGTH) {
            return -1;
        }

        return 0;
    }

    return -1;
}
Ejemplo n.º 2
0
static _Bool install_new_updater(void *new_updater_data, uint32_t new_updater_data_len)
{
#ifdef __WIN32__
    char new_path[MAX_PATH] = {0};
    FILE *file;

    memcpy(new_path, TOX_UPDATER_PATH, TOX_UPDATER_PATH_LEN);
    strcat(new_path, ".old");

    DeleteFile(new_path);
    MoveFile(TOX_UPDATER_PATH, new_path);

    file = fopen(TOX_UPDATER_PATH, "wb");
    if(!file) {
        LOG_TO_FILE("failed to write new updater");
        return 0;
    }

    fwrite(new_updater_data, 1, new_updater_data_len, file);

    fclose(file);
    return 1;
#else
    /* self update not implemented */
    return 0;
#endif
}
Ejemplo n.º 3
0
	Renderer::~Renderer()
	{
		// Unsubscribe from events
		UNSUBSCRIBE_FROM_EVENT(Event_World_Submit, EVENT_HANDLER_VARIANT(RenderablesAcquire));

		m_entities.clear();
		m_camera = nullptr;

		// Log to file as the renderer is no more
		LOG_TO_FILE(true);
	}
Ejemplo n.º 4
0
static void start_installation() {
    HWND desktop_shortcut_checkbox = GetDlgItem(main_window, ID_DESKTOP_SHORTCUT_CHECKBOX);
    HWND startmenu_shortcut_checkbox = GetDlgItem(main_window, ID_STARTMENU_SHORTCUT_CHECKBOX);
    HWND start_on_boot_checkbox = GetDlgItem(main_window, ID_START_ON_BOOT_CHECKBOX);
    HWND tox_url_checkbox = GetDlgItem(main_window, ID_TOX_URL_CHECKBOX);
    HWND browse_textbox = GetDlgItem(main_window, ID_BROWSE_TEXTBOX);

    _Bool create_desktop_shortcut, create_startmenu_shortcut, use_with_tox_url;

    wchar_t install_path[MAX_PATH];
    int install_path_len = GetWindowTextW(browse_textbox, install_path, MAX_PATH);

    if (install_path_len == 0) {
        MessageBox(main_window, "Please select a folder to install uTox in", "Error", MB_OK | MB_SETFOREGROUND);
        PostMessage(main_window, WM_APP, UTOX_INSTALL_ENDED, 0);
        return;
    }

    create_desktop_shortcut = Button_GetCheck(desktop_shortcut_checkbox);
    create_startmenu_shortcut = Button_GetCheck(startmenu_shortcut_checkbox);
    use_with_tox_url = Button_GetCheck(tox_url_checkbox);
    is_tox_set_start_on_boot = Button_GetCheck(start_on_boot_checkbox);

    LOG_TO_FILE("will install with options: %u %u %u %ls\n", create_desktop_shortcut, create_startmenu_shortcut, use_with_tox_url, install_path);

    if (MessageBox(main_window, "Are you sure you want to continue?", "uTox Updater", MB_YESNO | MB_SETFOREGROUND) != IDYES) {
        PostMessage(main_window, WM_APP, UTOX_INSTALL_ENDED, 0);
        return;
    }

    buttons_enable(0);
    int ret = install_tox(create_desktop_shortcut, create_startmenu_shortcut, use_with_tox_url, install_path, install_path_len);
    if (ret == 0) {
        set_current_status("installation complete");

        MessageBox(main_window, "Installation successful.", "uTox Updater", MB_OK | MB_SETFOREGROUND);
        open_utox_and_exit();
    } else if (ret == -1) {
        set_current_status("could not write to install directory.");
    } else if (ret == -2) {
        set_current_status("download error, please check your internet connection and try again.");
    } else {
        set_current_status("error during installation");

        MessageBox(main_window, "Installation failed. If it's not an internet issue please send the log file (tox_log.txt) to the developers.", "uTox Updater", MB_OK | MB_SETFOREGROUND);
        exit(0);
    }

    PostMessage(main_window, WM_APP, UTOX_INSTALL_ENDED, 0);
    buttons_enable(1);
}
Ejemplo n.º 5
0
ASTConsumer::ASTConsumer(clang::ASTContext& context, cldb::Database& db, const ReflectionSpecs& rspecs, const std::string& ast_log)
	: m_ASTContext(context)
	, m_DB(db)
	, m_ReflectionSpecs(rspecs)
	, m_PrintingPolicy(0)
	, m_AllowReflect(false)
{
	LOG_TO_STDOUT(warnings, INFO);

	if (ast_log != "")
		LOG_TO_FILE(ast, ALL, ast_log.c_str());

	m_PrintingPolicy = new clang::PrintingPolicy(m_ASTContext.getLangOpts());
}
Ejemplo n.º 6
0
	Renderer::Renderer(Context* context) : ISubsystem(context)
	{	
		m_near_plane	= 0.0f;
		m_far_plane		= 0.0f;
		m_frame_num		= 0;
		m_flags			|= Render_Gizmo_Transform;
		m_flags			|= Render_Gizmo_Grid;
		m_flags			|= Render_Gizmo_Lights;
		m_flags			|= Render_Gizmo_Physics;
		m_flags			|= Render_PostProcess_Bloom;	
		m_flags			|= Render_PostProcess_SSAO;	
		m_flags			|= Render_PostProcess_MotionBlur;
		m_flags			|= Render_PostProcess_TAA;
		m_flags			|= Render_PostProcess_Sharpening;	
		m_flags			|= Render_PostProcess_SSR;
		//m_flags		|= Render_PostProcess_Dithering;			// Diasbled by default: It's only needed in very dark scenes to fix smooth color gradients
		//m_flags		|= Render_PostProcess_ChromaticAberration;	// Disabled by default: It doesn't improve the image quality, it's more of a stylistic effect		
		//m_flags		|= Render_PostProcess_FXAA;					// Disabled by default: TAA is superior
		
		// Create RHI device
		m_rhi_device = make_shared<RHI_Device>();
		if (!m_rhi_device->IsInitialized())
		{
			LOG_ERROR("Failed to create device");
			return;
		}

		// Create command list
		m_cmd_list = make_shared<RHI_CommandList>(m_rhi_device.get(), m_context->GetSubsystem<Profiler>().get());

		// Log on-screen as the renderer is ready
		LOG_TO_FILE(false);
		m_initialized = true;

		// Subscribe to events
		SUBSCRIBE_TO_EVENT(Event_World_Submit, EVENT_HANDLER_VARIANT(RenderablesAcquire));
	}
Ejemplo n.º 7
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int nCmdShow)
{
    utox_mutex_handle = CreateMutex(NULL, 0, UTOX_TITLE);

    if (!utox_mutex_handle) {
        return 0;
    }

    if (GetLastError() == ERROR_ALREADY_EXISTS) {
        HWND window = FindWindow(UTOX_TITLE, NULL);

        /* uTox is running. */
        if (window) {
            SetForegroundWindow(window);
        }

        return 0;
    }

    MY_CMD_ARGS = cmd;
    MY_HINSTANCE = hInstance;

    TOX_UPDATER_PATH_LEN = GetModuleFileName(NULL, TOX_UPDATER_PATH, MAX_PATH);
    TOX_UPDATER_PATH[TOX_UPDATER_PATH_LEN] = 0;

    {
        char path[MAX_PATH], *s;
        memcpy(path, TOX_UPDATER_PATH, TOX_UPDATER_PATH_LEN + 1);
        s = path + TOX_UPDATER_PATH_LEN;
        while(*s != '\\') {
            s--;
        }

        *s = 0;
        SetCurrentDirectory(path);
    }

    LPWSTR *arglist;
    int argc, i;

    init_tox_version_name();

    /* Convert PSTR command line args from windows to argc */
    arglist = CommandLineToArgvW(GetCommandLineW(), &argc);
    if( NULL != arglist ){
        for (i = 0; i < argc; i++) {
            if(wcscmp(arglist[i], L"--uninstall") == 0) {
                if (is_tox_installed) {
                    uninstall_tox();
                    return 0;
                }
            }
        }
    }

    LOG_FILE = fopen("tox_log.txt", "w");

    /* initialize winsock */
    WSADATA wsaData;
    if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
        LOG_TO_FILE("WSAStartup failed\n");
        return 1;
    }

    if (IsWindowsVistaOrGreater()) {
        /* check if we are on a 64-bit system */
        _Bool iswow64 = 0;
        _Bool (WINAPI *fnIsWow64Process)(HANDLE, _Bool*)  = (void*)GetProcAddress(GetModuleHandleA("kernel32"),"IsWow64Process");
        if(fnIsWow64Process) {
            fnIsWow64Process(GetCurrentProcess(), &iswow64);
        }

        if(iswow64) {
            /* replace the arch in the GET_NAME/TOX_VERSION_NAME strings (todo: not use constants for offsets) */
            GET_NAME[3] = '6';
            GET_NAME[4] = '4';
            TOX_VERSION_NAME[0] = '6';
            TOX_VERSION_NAME[1] = '4';
            LOG_TO_FILE("detected 64bit system\n");
        } else {
            GET_NAME[3] = '3';
            GET_NAME[4] = '2';
            TOX_VERSION_NAME[0] = '3';
            TOX_VERSION_NAME[1] = '2';
            LOG_TO_FILE("detected 32bit system\n");
        }
    } else {
        GET_NAME[3] = 'x';
        GET_NAME[4] = 'p';
        TOX_VERSION_NAME[0] = 'x';
        TOX_VERSION_NAME[1] = 'p';
        LOG_TO_FILE("detected XP system\n");
    }

    /* init common controls */
    INITCOMMONCONTROLSEX InitCtrlEx;

    InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
    InitCommonControlsEx(&InitCtrlEx);

    main_window = CreateDialog(MY_HINSTANCE, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, MainDialogProc);

    if (!main_window) {
        LOG_TO_FILE("error creating main window %lu\n", GetLastError());
        exit(0);
    }

    progressbar = GetDlgItem(main_window, ID_PROGRESSBAR);
    set_download_progress(0);
    status_label = GetDlgItem(main_window, IDC_STATUS_LABEL);

    if (!is_tox_installed) {
        // show installer controls
        HWND desktop_shortcut_checkbox = GetDlgItem(main_window, ID_DESKTOP_SHORTCUT_CHECKBOX);
        Button_SetCheck(desktop_shortcut_checkbox, 1);
        ShowWindow(desktop_shortcut_checkbox, SW_SHOW);

        HWND startmenu_shortcut_checkbox = GetDlgItem(main_window, ID_STARTMENU_SHORTCUT_CHECKBOX);
        Button_SetCheck(startmenu_shortcut_checkbox, 1);
        ShowWindow(startmenu_shortcut_checkbox, SW_SHOW);

        HWND start_on_boot_checkbox = GetDlgItem(main_window, ID_START_ON_BOOT_CHECKBOX);
        Button_SetCheck(start_on_boot_checkbox, 1);
        ShowWindow(start_on_boot_checkbox, SW_SHOW);

        ShowWindow(GetDlgItem(main_window, ID_TOX_URL_CHECKBOX), SW_SHOW);

        wchar_t appdatalocal_path[MAX_PATH] = {0};
        if (SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, appdatalocal_path) == S_OK) {
            set_utox_path(appdatalocal_path);
        }

        Button_Enable(GetDlgItem(main_window, ID_INSTALL_BUTTON), 0);
        ShowWindow(GetDlgItem(main_window, ID_INSTALL_BUTTON), SW_SHOW);

        Edit_SetReadOnly(GetDlgItem(main_window, ID_BROWSE_TEXTBOX), 1);
        ShowWindow(GetDlgItem(main_window, ID_BROWSE_TEXTBOX), SW_SHOW);
        ShowWindow(GetDlgItem(main_window, ID_BROWSE_BUTTON), SW_SHOW);
        ShowWindow(GetDlgItem(main_window, IDC_INSTALL_FOLDER_LABEL), SW_SHOW);
        ShowWindow(main_window, SW_SHOW);
    }

    _beginthread(check_updates, 0, NULL);

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0) > 0) {
        DispatchMessage(&msg);
    }

    open_utox_and_exit();

    return 0;
}
Ejemplo n.º 8
0
/* return 0 on success.
 * return -1 if could not write file.
 * return -2 if download failed.
 */
static int install_tox(int create_desktop_shortcut, int create_startmenu_shortcut, int use_with_tox_url, wchar_t *install_path, int install_path_len) {

    char dir[MAX_PATH];

    wchar_t selfpath[MAX_PATH];
    GetModuleFileNameW(MY_HINSTANCE, selfpath, MAX_PATH);

    SHCreateDirectoryExW(NULL, install_path, NULL);
    SetCurrentDirectoryW(install_path);
    if (CopyFileW(selfpath, L""TOX_UPDATER_FILENAME, 0) == 0)
        return -1;

    int ret = write_uninstall();
    if (ret != 0)
        return ret;

    set_current_status("downloading and installing tox...");

    ret = download_and_install_new_utox_version();
    if (ret != 0)
        return ret;

    HRESULT hr;
    HKEY key;

    if (create_desktop_shortcut || create_startmenu_shortcut) {
        hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
        if(SUCCEEDED(hr)) {
            //start menu
            IShellLink* psl;

            // Get a pointer to the IShellLink interface. It is assumed that CoInitialize
            // has already been called.
            hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl);
            if (SUCCEEDED(hr)) {
                IPersistFile* ppf;

                // Set the path to the shortcut target and add the description.

                GetCurrentDirectory(MAX_PATH, dir);
                psl->lpVtbl->SetWorkingDirectory(psl, dir);
                strcat(dir, "\\"TOX_UPDATER_FILENAME);
                psl->lpVtbl->SetPath(psl, dir);
                psl->lpVtbl->SetDescription(psl, "Tox");

                // Query IShellLink for the IPersistFile interface, used for saving the
                // shortcut in persistent storage.
                hr = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);

                if (SUCCEEDED(hr)) {
                    wchar_t wsz[MAX_PATH + 64];
                    if (create_startmenu_shortcut) {
                        hr = SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, wsz);
                        if (SUCCEEDED(hr)) {
                            LOG_TO_FILE("%ls\n", wsz);
                            wcscat(wsz, L"\\Programs\\Tox.lnk");
                            hr = ppf->lpVtbl->Save(ppf, wsz, TRUE);
                        }
                    }

                    if (create_desktop_shortcut) {
                        hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, wsz);
                        if (SUCCEEDED(hr)) {
                            wcscat(wsz, L"\\Tox.lnk");
                            hr = ppf->lpVtbl->Save(ppf, wsz, TRUE);
                        }
                    }

                    ppf->lpVtbl->Release(ppf);
                }
                psl->lpVtbl->Release(psl);
            }
        }
    }

    if (use_with_tox_url) {
        GetCurrentDirectory(MAX_PATH, dir);
        strcat(dir, "\\" TOX_EXE_NAME);

        char str[MAX_PATH];

        if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\tox", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS) {
            LOG_TO_FILE("nice\n");
            RegSetValueEx(key, NULL, 0, REG_SZ, (BYTE*)"URL:Tox Protocol", sizeof("URL:Tox Protocol"));
            RegSetValueEx(key, "URL Protocol", 0, REG_SZ, (BYTE*)"", sizeof(""));

            HKEY key2;
            if (RegCreateKeyEx(key, "DefaultIcon", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key2, NULL) == ERROR_SUCCESS) {
                int i = sprintf(str, "%s,101", dir) + 1;
                RegSetValueEx(key2, NULL, 0, REG_SZ, (BYTE*)str, i);
            }

            if (RegCreateKeyEx(key, "shell", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key2, NULL) == ERROR_SUCCESS) {
                if (RegCreateKeyEx(key2, "open", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS) {
                    if (RegCreateKeyEx(key, "command", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key2, NULL) == ERROR_SUCCESS) {
                        int i = sprintf(str, "%s %%1", dir) + 1;
                        RegSetValueEx(key2, NULL, 0, REG_SZ, (BYTE*)str, i);
                    }
                }
            }
        }
    }

    if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\uTox", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS) {
            wchar_t icon[install_path_len + 64];
            wchar_t uninstall[install_path_len + 64];
            memcpy(icon, install_path, install_path_len * 2);
            icon[install_path_len] = 0;
            uninstall[0] = 0;
            wcscat(uninstall, L"cmd /C start \"\" /MIN \"");

            wcscat(icon, L"\\uTox.exe");
            wcscat(uninstall, install_path);
            wcscat(uninstall, L"\\uninstall.bat\"");
    
            RegSetValueEx(key, NULL, 0, REG_SZ, (BYTE*)"", sizeof(""));
            RegSetValueEx(key, "DisplayName", 0, REG_SZ, (BYTE*)"uTox", sizeof("uTox"));
            RegSetValueExW(key, L"InstallLocation", 0, REG_SZ, (BYTE*)install_path, wcslen(install_path) * 2);
            RegSetValueExW(key, L"DisplayIcon", 0, REG_SZ, (BYTE*)icon, wcslen(icon) * 2);
            RegSetValueExW(key, L"UninstallString", 0, REG_SZ, (BYTE*)uninstall, wcslen(uninstall) * 2);
    }
    return 0;
}
Ejemplo n.º 9
0
static int check_new_version()
{
    FILE *file;
    char *new_version_data;
    uint32_t len;

    new_version_data = download_loop_all_host_ips(0, TOX_DOWNNLOAD_HOSTS, NUMBER_UPDATE_HOSTS, VERSION_FILE_NAME, strlen(VERSION_FILE_NAME), &len, 7 + 4, TOX_SELF_PUBLICK_KEY, 0, 0);

    if (!new_version_data) {
        LOG_TO_FILE("version download failed\n");
        return -1;
    }

    if (len != 7 + 4) {
        LOG_TO_FILE("invalid version length (%u)\n", len);
        free(new_version_data);
        return -1;
    }

    char str[7];
    memcpy(str, new_version_data + 4, 7);

    if (str[6] > VERSION + '0') {
        LOG_TO_FILE("new updater version available (%u)\n", str[6]);

        char *new_updater_data;
        uint32_t new_updater_data_len;

        new_updater_data = download_new_updater(&new_updater_data_len);

        if (!new_updater_data) {
            LOG_TO_FILE("self update download failed\n");
        } else {
            if (install_new_updater(new_updater_data, new_updater_data_len)) {
                LOG_TO_FILE("successful self update\n");

                free(new_version_data);

                restart_updater();
            }
        }
    }

    str[6] = 0;

    LOG_TO_FILE("Version: %s\n", str);
    free(new_version_data);

    if (memcmp(TOX_VERSION_NAME + 2, str, 6) == 0) {
        /* check if we already have the exe */
        file = fopen(TOX_EXE_NAME, "rb");
        if (!file) {
            LOG_TO_FILE("We don't have the file\n");
            fclose(file);
            return 1;
        }

        return 0;
    }

    memcpy(TOX_VERSION_NAME + 2, str, 7);
    return 1;
}