mirror of
https://github.com/blender/blender
synced 2026-09-27 01:34:15 +03:00
Support bundled `certifi` certificates on MS-Windows which were already supported on macOS & portable Linux installs. WIN32 relied on the systems certificate store which some users had trouble with - failing to connect to Blender's extensions repository for example. Note that these are added to the locally installed certificates which keep working as before. Details: - Use `SSL_CERT_FILE` environment variable, already used on macOS & Linux. - Use `_wputenv_s` for `uputenv` as WIN32 `SetEnvironmentVariableW` doesn't update the C run-time environment variable returned by `getenv` which OpenSSL uses to access `SSL_CERT_FILE`. - Note this changes `BLI_setenv` on WIN32, a null value no longer removes the variable, it's left defined as an empty string: `BLI_getenv` already accounted for this, returning null for empty values. - This resolves HTTPS connection some users were experiencing using Python's built-in `urllib` - which impacted extension. Ref !162174
174 lines
3.3 KiB
C++
174 lines
3.3 KiB
C++
/* SPDX-FileCopyrightText: 2012 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup intern_utf_conv
|
|
*/
|
|
|
|
#ifndef _WIN32_IE
|
|
# define _WIN32_IE 0x0501
|
|
#endif
|
|
|
|
#include "utf_winfunc.hh"
|
|
#include "utfconv.hh"
|
|
#include <cwchar>
|
|
#include <io.h>
|
|
#include <windows.h>
|
|
|
|
FILE *ufopen(const char *filename, const char *mode)
|
|
{
|
|
FILE *f = nullptr;
|
|
UTF16_ENCODE(filename);
|
|
UTF16_ENCODE(mode);
|
|
|
|
if (filename_16 && mode_16) {
|
|
f = _wfopen(filename_16, mode_16);
|
|
}
|
|
|
|
UTF16_UN_ENCODE(mode);
|
|
UTF16_UN_ENCODE(filename);
|
|
|
|
if (!f) {
|
|
if ((f = fopen(filename, mode))) {
|
|
printf("WARNING: %s is not utf path. Please update it.\n", filename);
|
|
}
|
|
}
|
|
|
|
return f;
|
|
}
|
|
|
|
int uopen(const char *filename, int oflag, int pmode)
|
|
{
|
|
int f = -1;
|
|
UTF16_ENCODE(filename);
|
|
|
|
if (filename_16) {
|
|
f = _wopen(filename_16, oflag, pmode);
|
|
}
|
|
|
|
UTF16_UN_ENCODE(filename);
|
|
|
|
if (f == -1) {
|
|
if ((f = open(filename, oflag, pmode)) != -1) {
|
|
printf("WARNING: %s is not utf path. Please update it.\n", filename);
|
|
}
|
|
}
|
|
|
|
return f;
|
|
}
|
|
|
|
int uaccess(const char *filename, int mode)
|
|
{
|
|
int r = -1;
|
|
UTF16_ENCODE(filename);
|
|
|
|
if (filename_16) {
|
|
r = _waccess(filename_16, mode);
|
|
}
|
|
|
|
UTF16_UN_ENCODE(filename);
|
|
|
|
return r;
|
|
}
|
|
|
|
int urename(const char *oldname, const char *newname, const bool do_replace)
|
|
{
|
|
int r = -1;
|
|
UTF16_ENCODE(oldname);
|
|
UTF16_ENCODE(newname);
|
|
|
|
if (oldname_16 && newname_16) {
|
|
/* Closer to UNIX `rename` behavior, as it at least allows to replace an existing file.
|
|
* Return value logic is inverted however (returns non-zero on sucess, 0 on failure).
|
|
* Note that the operation will still fail if the 'newname' existing file is opened anywhere.
|
|
*/
|
|
r = (MoveFileExW(oldname_16, newname_16, do_replace ? MOVEFILE_REPLACE_EXISTING : 0) == 0);
|
|
}
|
|
|
|
UTF16_UN_ENCODE(newname);
|
|
UTF16_UN_ENCODE(oldname);
|
|
return r;
|
|
}
|
|
|
|
int umkdir(const char *pathname)
|
|
{
|
|
|
|
BOOL r = 0;
|
|
UTF16_ENCODE(pathname);
|
|
|
|
if (pathname_16) {
|
|
r = CreateDirectoryW(pathname_16, NULL);
|
|
}
|
|
|
|
UTF16_UN_ENCODE(pathname);
|
|
|
|
return r ? 0 : -1;
|
|
}
|
|
|
|
char *u_alloc_getenv(const char *varname)
|
|
{
|
|
char *r = nullptr;
|
|
wchar_t *str;
|
|
UTF16_ENCODE(varname);
|
|
if (varname_16) {
|
|
str = _wgetenv(varname_16);
|
|
r = alloc_utf_8_from_16(str, 0);
|
|
}
|
|
UTF16_UN_ENCODE(varname);
|
|
|
|
return r;
|
|
}
|
|
void u_free_getenv(char *val)
|
|
{
|
|
free(val);
|
|
}
|
|
|
|
int uput_getenv(const char *varname, char *value, size_t buffsize)
|
|
{
|
|
int r = 0;
|
|
wchar_t *str;
|
|
|
|
if (!buffsize) {
|
|
return r;
|
|
}
|
|
|
|
UTF16_ENCODE(varname);
|
|
if (varname_16) {
|
|
str = _wgetenv(varname_16);
|
|
conv_utf_16_to_8(str, value, buffsize);
|
|
r = 1;
|
|
}
|
|
UTF16_UN_ENCODE(varname);
|
|
|
|
if (!r) {
|
|
value[0] = 0;
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
int uputenv(const char *name, const char *value)
|
|
{
|
|
int r = -1;
|
|
/* `_wputenv_s` doesn't support a null value, an empty value removes the variable. */
|
|
if (value == nullptr) {
|
|
value = "";
|
|
}
|
|
|
|
UTF16_ENCODE(name);
|
|
|
|
if (name_16) {
|
|
UTF16_ENCODE(value);
|
|
if (value_16) {
|
|
/* Not `SetEnvironmentVariableW` as it doesn't update the environment `getenv` reads,
|
|
* `_wputenv_s` updates that as well as the block child processes inherit. */
|
|
r = (_wputenv_s(name_16, value_16) == 0) ? 0 : -1;
|
|
}
|
|
UTF16_UN_ENCODE(value);
|
|
}
|
|
|
|
UTF16_UN_ENCODE(name);
|
|
|
|
return r;
|
|
}
|