Adds support for utf paths on Windows.

Not all file formats/calls are supported yet. It will be expended.

Please from now on use BLI_fopen, BLI_* for file manipulations.
For non-windows systems BLI_fopen just calls fopen.
For Windows, the utf-8 string is translated to utf-16 string in order to call UTF version of the function.
This commit is contained in:
2012-03-20 02:17:37 +00:00
parent deea1f38b1
commit f11a6d3a84
66 changed files with 1012 additions and 175 deletions

View File

@@ -340,6 +340,7 @@ def creator(env):
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs.append(env['BF_PTHREADS_INC']) incs.append(env['BF_PTHREADS_INC'])
incs.append('#/intern/utfconv')
env.Append(CPPDEFINES=defs) env.Append(CPPDEFINES=defs)
env.Append(CPPPATH=incs) env.Append(CPPPATH=incs)

View File

@@ -66,3 +66,8 @@ if(WITH_CYCLES)
add_subdirectory(cycles) add_subdirectory(cycles)
endif() endif()
#Only Windows needs utf16 converter
if(WIN32)
add_subdirectory(utfconv)
endif()

View File

@@ -3,6 +3,7 @@ Import ('env')
SConscript(['audaspace/SConscript', SConscript(['audaspace/SConscript',
'string/SConscript', 'string/SConscript',
'utfconv/SConscript',
'ghost/SConscript', 'ghost/SConscript',
'guardedalloc/SConscript', 'guardedalloc/SConscript',
'moto/SConscript', 'moto/SConscript',

View File

@@ -281,6 +281,10 @@ elseif(WIN32)
${WINTAB_INC} ${WINTAB_INC}
) )
list(APPEND INC
../utfconv
)
list(APPEND SRC list(APPEND SRC
intern/GHOST_DisplayManagerWin32.cpp intern/GHOST_DisplayManagerWin32.cpp
intern/GHOST_SystemWin32.cpp intern/GHOST_SystemWin32.cpp

View File

@@ -110,6 +110,7 @@ else:
if window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'): if window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'):
incs = env['BF_WINTAB_INC'] + ' ' + incs incs = env['BF_WINTAB_INC'] + ' ' + incs
incs += ' ../utfconv'
if window_system in ('win32-vc', 'win64-vc'): if window_system in ('win32-vc', 'win64-vc'):
env.BlenderLib ('bf_intern_ghost', sources, Split(incs), defines=defs, libtype=['intern','player'], priority = [40,15]) #, cc_compileflags=env['CCFLAGS'].append('/WX') ) env.BlenderLib ('bf_intern_ghost', sources, Split(incs), defines=defs, libtype=['intern','player'], priority = [40,15]) #, cc_compileflags=env['CCFLAGS'].append('/WX') )

View File

@@ -34,6 +34,9 @@
#include "GHOST_DropTargetWin32.h" #include "GHOST_DropTargetWin32.h"
#include <ShellApi.h> #include <ShellApi.h>
#include "utf_winfunc.h"
#include "utfconv.h"
#ifdef GHOST_DEBUG #ifdef GHOST_DEBUG
// utility // utility
void printLastError(void); void printLastError(void);
@@ -267,20 +270,12 @@ void * GHOST_DropTargetWin32::getDropDataAsFilenames(IDataObject * pDataObject)
{ {
if ( ::DragQueryFileW ( hdrop, nfile, fpath, MAX_PATH ) > 0 ) if ( ::DragQueryFileW ( hdrop, nfile, fpath, MAX_PATH ) > 0 )
{ {
if ( !WideCharToANSI(fpath, temp_path) ) if ( !(temp_path = alloc_utf_8_from_16(fpath, 0)) )
{ {
continue; continue;
} }
// Just ignore paths that could not be converted verbatim. // Just ignore paths that could not be converted verbatim.
if (strpbrk(temp_path, "?"))
{
#ifdef GHOST_DEBUG
::printf("\ndiscarding path that contains illegal characters: %s", temp_path);
#endif // GHOST_DEBUG
::free(temp_path);
temp_path = NULL;
continue;
}
strArray->strings[nvalid] = (GHOST_TUns8*) temp_path; strArray->strings[nvalid] = (GHOST_TUns8*) temp_path;
strArray->count = nvalid+1; strArray->count = nvalid+1;
nvalid++; nvalid++;
@@ -309,7 +304,7 @@ void * GHOST_DropTargetWin32::getDropDataAsString(IDataObject * pDataObject)
if(pDataObject->GetData(&fmtetc, &stgmed) == S_OK) if(pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
{ {
LPCWSTR wstr = (LPCWSTR)::GlobalLock(stgmed.hGlobal); LPCWSTR wstr = (LPCWSTR)::GlobalLock(stgmed.hGlobal);
if ( !WideCharToANSI(wstr, tmp_string) ) if ( !(tmp_string = alloc_utf_8_from_16((wchar_t*)wstr, 0)) )
{ {
::GlobalUnlock(stgmed.hGlobal); ::GlobalUnlock(stgmed.hGlobal);
return NULL; return NULL;

View File

@@ -35,6 +35,7 @@
#define _WIN32_IE 0x0501 #define _WIN32_IE 0x0501
#endif #endif
#include <shlobj.h> #include <shlobj.h>
#include "utfconv.h"
#if defined(__MINGW32__) || defined(__CYGWIN__) #if defined(__MINGW32__) || defined(__CYGWIN__)
@@ -70,11 +71,14 @@ GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const
{ {
static char knownpath[MAX_PATH]; static char knownpath[MAX_PATH*3] = {0}; /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath); wchar_t knownpath_16[MAX_PATH];
HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
if (hResult == S_OK) if (hResult == S_OK)
{ {
conv_utf_16_to_8(knownpath_16,knownpath,MAX_PATH*3);
return (GHOST_TUns8*)knownpath; return (GHOST_TUns8*)knownpath;
} }
@@ -83,11 +87,14 @@ const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const
const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const
{ {
static char knownpath[MAX_PATH]; static char knownpath[MAX_PATH*3] = {0};
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath); wchar_t knownpath_16[MAX_PATH];
HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
if (hResult == S_OK) if (hResult == S_OK)
{ {
conv_utf_16_to_8(knownpath_16,knownpath,MAX_PATH*3);
return (GHOST_TUns8*)knownpath; return (GHOST_TUns8*)knownpath;
} }
@@ -96,8 +103,11 @@ const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const
const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const
{ {
static char fullname[MAX_PATH]; static char fullname[MAX_PATH*3] = {0};
if(GetModuleFileName(0, fullname, MAX_PATH)) { wchar_t fullname_16[MAX_PATH*3];
if(GetModuleFileNameW(0, fullname_16, MAX_PATH)) {
conv_utf_16_to_8(fullname_16,fullname,MAX_PATH*3);
return (GHOST_TUns8*)fullname; return (GHOST_TUns8*)fullname;
} }
@@ -107,5 +117,7 @@ const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const
void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char* filename) const void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char* filename) const
{ {
/* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */ /* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */
SHAddToRecentDocs(SHARD_PATH,filename); UTF16_ENCODE(filename)
SHAddToRecentDocs(SHARD_PATHW,filename_16);
UTF16_UN_ENCODE(filename)
} }

View File

@@ -60,6 +60,8 @@
#endif #endif
#endif #endif
#include "utfconv.h"
#include "GHOST_DisplayManagerWin32.h" #include "GHOST_DisplayManagerWin32.h"
#include "GHOST_EventButton.h" #include "GHOST_EventButton.h"
#include "GHOST_EventCursor.h" #include "GHOST_EventCursor.h"
@@ -292,8 +294,8 @@ bool GHOST_SystemWin32::processEvents(bool waitForEvent)
} }
// Process all the events waiting for us // Process all the events waiting for us
while (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE) != 0) { while (::PeekMessageW(&msg, 0, 0, 0, PM_REMOVE) != 0) {
::DispatchMessage(&msg); ::DispatchMessageW(&msg);
anyProcessed = true; anyProcessed = true;
} }
} while (waitForEvent && !anyProcessed); } while (waitForEvent && !anyProcessed);
@@ -394,7 +396,7 @@ GHOST_TSuccess GHOST_SystemWin32::init()
} }
if (success) { if (success) {
WNDCLASS wc; WNDCLASSW wc;
wc.style= CS_HREDRAW | CS_VREDRAW; wc.style= CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc= s_wndProc; wc.lpfnWndProc= s_wndProc;
wc.cbClsExtra= 0; wc.cbClsExtra= 0;
@@ -408,10 +410,10 @@ GHOST_TSuccess GHOST_SystemWin32::init()
wc.hCursor = ::LoadCursor(0, IDC_ARROW); wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.hbrBackground= (HBRUSH)::GetStockObject(BLACK_BRUSH); wc.hbrBackground= (HBRUSH)::GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = 0; wc.lpszMenuName = 0;
wc.lpszClassName= GHOST_WindowWin32::getWindowClassName(); wc.lpszClassName= L"GHOST_WindowClass";
// Use RegisterClassEx for setting small icon // Use RegisterClassEx for setting small icon
if (::RegisterClass(&wc) == 0) { if (::RegisterClassW(&wc) == 0) {
success = GHOST_kFailure; success = GHOST_kFailure;
} }
} }
@@ -719,15 +721,17 @@ GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINP
char utf8_char[6] = {0}; char utf8_char[6] = {0};
char ascii = 0; char ascii = 0;
wchar_t utf16[2]={0}; wchar_t utf16[3]={0};
BYTE state[256] ={0}; BYTE state[256] ={0};
GetKeyboardState(state); int r;
GetKeyboardState((PBYTE)state);
if(ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout)) if(r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout))
WideCharToMultiByte(CP_UTF8, 0,
(wchar_t*)utf16, 1, if((r>0 && r<3)){utf16[r]=0;
(LPSTR) utf8_char, 5,
NULL,NULL); else *utf8_char = 0; conv_utf_16_to_8(utf16,utf8_char,6);}
else if (r==-1) utf8_char[0] = '\0';
@@ -1189,8 +1193,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
* DefWindowProc returns. * DefWindowProc returns.
*/ */
break; break;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Other events // Other events
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
case WM_GETTEXT: case WM_GETTEXT:
@@ -1239,17 +1242,17 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
} }
if (!eventHandled) if (!eventHandled)
lResult = ::DefWindowProc(hwnd, msg, wParam, lParam); lResult = ::DefWindowProcW(hwnd, msg, wParam, lParam);
return lResult; return lResult;
} }
GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const
{ {
wchar_t *buffer;
char *temp_buff; char *temp_buff;
if ( IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) { if ( IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) {
wchar_t *buffer;
size_t len = 0; size_t len = 0;
HANDLE hData = GetClipboardData( CF_UNICODETEXT ); HANDLE hData = GetClipboardData( CF_UNICODETEXT );
if (hData == NULL) { if (hData == NULL) {
@@ -1262,9 +1265,32 @@ GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const
return NULL; return NULL;
} }
len = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL); temp_buff = alloc_utf_8_from_16(buffer,0);
temp_buff = (char*) malloc(len);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, temp_buff, len, NULL, NULL); /* Buffer mustn't be accessed after CloseClipboard
it would like accessing free-d memory */
GlobalUnlock( hData );
CloseClipboard();
return (GHOST_TUns8*)temp_buff;
} else if ( IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(NULL) ) {
char *buffer;
size_t len = 0;
HANDLE hData = GetClipboardData( CF_TEXT );
if (hData == NULL) {
CloseClipboard();
return NULL;
}
buffer = (char*)GlobalLock( hData );
if (!buffer) {
CloseClipboard();
return NULL;
}
len = strlen(buffer);
temp_buff = (char*) malloc(len+1);
strncpy(temp_buff, buffer, len);
temp_buff[len] = '\0';
/* Buffer mustn't be accessed after CloseClipboard /* Buffer mustn't be accessed after CloseClipboard
it would like accessing free-d memory */ it would like accessing free-d memory */
@@ -1281,20 +1307,19 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
{ {
if(selection) {return;} // for copying the selection, used on X11 if(selection) {return;} // for copying the selection, used on X11
if (OpenClipboard(NULL)) { if(OpenClipboard(NULL)) {
HLOCAL clipbuffer; HLOCAL clipbuffer;
wchar_t *data; wchar_t *data;
if (buffer) { if (buffer) {
size_t len = count_utf_16_from_8(buffer);
EmptyClipboard(); EmptyClipboard();
int wlen = MultiByteToWideChar(CP_UTF8, 0, buffer, -1, NULL, 0); clipbuffer = LocalAlloc(LMEM_FIXED,sizeof(wchar_t) * len);
clipbuffer = LocalAlloc(LMEM_FIXED, wlen * sizeof(wchar_t));
data = (wchar_t*)GlobalLock(clipbuffer); data = (wchar_t*)GlobalLock(clipbuffer);
MultiByteToWideChar(CP_UTF8, 0, buffer, -1, data, wlen); conv_utf_8_to_16(buffer, data, len);
LocalUnlock(clipbuffer); LocalUnlock(clipbuffer);
SetClipboardData(CF_UNICODETEXT,clipbuffer); SetClipboardData(CF_UNICODETEXT,clipbuffer);
} }

View File

@@ -41,6 +41,8 @@
#include "GHOST_WindowWin32.h" #include "GHOST_WindowWin32.h"
#include "GHOST_SystemWin32.h" #include "GHOST_SystemWin32.h"
#include "GHOST_DropTargetWin32.h" #include "GHOST_DropTargetWin32.h"
#include "utfconv.h"
#include "utf_winfunc.h"
// Need glew for some defines // Need glew for some defines
#include <GL/glew.h> #include <GL/glew.h>
@@ -64,7 +66,7 @@
#endif #endif
#endif #endif
LPCSTR GHOST_WindowWin32::s_windowClassName = "GHOST_WindowClass"; wchar_t* GHOST_WindowWin32::s_windowClassName = L"GHOST_WindowClass";
const int GHOST_WindowWin32::s_maxTitleLength = 128; const int GHOST_WindowWin32::s_maxTitleLength = 128;
HGLRC GHOST_WindowWin32::s_firsthGLRc = NULL; HGLRC GHOST_WindowWin32::s_firsthGLRc = NULL;
HDC GHOST_WindowWin32::s_firstHDC = NULL; HDC GHOST_WindowWin32::s_firstHDC = NULL;
@@ -234,9 +236,10 @@ GHOST_WindowWin32::GHOST_WindowWin32(
height = rect.bottom - rect.top; height = rect.bottom - rect.top;
} }
m_hWnd = ::CreateWindow( wchar_t * title_16 = alloc_utf16_from_8((char*)(const char*)title,0);
m_hWnd = ::CreateWindowW(
s_windowClassName, // pointer to registered class name s_windowClassName, // pointer to registered class name
title, // pointer to window name title_16, // pointer to window name
wintype, // window style wintype, // window style
left, // horizontal position of window left, // horizontal position of window
top, // vertical position of window top, // vertical position of window
@@ -246,11 +249,13 @@ GHOST_WindowWin32::GHOST_WindowWin32(
0, // handle to menu or child-window identifier 0, // handle to menu or child-window identifier
::GetModuleHandle(0), // handle to application instance ::GetModuleHandle(0), // handle to application instance
0); // pointer to window-creation data 0); // pointer to window-creation data
free(title_16);
} }
else { else {
m_hWnd = ::CreateWindow( wchar_t * title_16 = alloc_utf16_from_8((char*)(const char*)title,0);
m_hWnd = ::CreateWindowW(
s_windowClassName, // pointer to registered class name s_windowClassName, // pointer to registered class name
title, // pointer to window name title_16, // pointer to window name
WS_POPUP | WS_MAXIMIZE, // window style WS_POPUP | WS_MAXIMIZE, // window style
left, // horizontal position of window left, // horizontal position of window
top, // vertical position of window top, // vertical position of window
@@ -260,6 +265,7 @@ GHOST_WindowWin32::GHOST_WindowWin32(
0, // handle to menu or child-window identifier 0, // handle to menu or child-window identifier
::GetModuleHandle(0), // handle to application instance ::GetModuleHandle(0), // handle to application instance
0); // pointer to window-creation data 0); // pointer to window-creation data
free(title_16);
} }
if (m_hWnd) { if (m_hWnd) {
// Register this window as a droptarget. Requires m_hWnd to be valid. // Register this window as a droptarget. Requires m_hWnd to be valid.
@@ -433,13 +439,15 @@ HWND GHOST_WindowWin32::getHWND() const
void GHOST_WindowWin32::setTitle(const STR_String& title) void GHOST_WindowWin32::setTitle(const STR_String& title)
{ {
::SetWindowText(m_hWnd, title); wchar_t * title_16 = alloc_utf16_from_8((char*)(const char*)title, 0);
::SetWindowTextW(m_hWnd, (wchar_t*)title_16);
free(title_16);
} }
void GHOST_WindowWin32::getTitle(STR_String& title) const void GHOST_WindowWin32::getTitle(STR_String& title) const
{ {
char buf[s_maxTitleLength]; char buf[s_maxTitleLength];/*CHANGE + never used yet*/
::GetWindowText(m_hWnd, buf, s_maxTitleLength); ::GetWindowText(m_hWnd, buf, s_maxTitleLength);
STR_String temp (buf); STR_String temp (buf);
title = buf; title = buf;

View File

@@ -236,7 +236,7 @@ public:
* Returns the name of the window class. * Returns the name of the window class.
* @return The name of the window class. * @return The name of the window class.
*/ */
static LPCSTR getWindowClassName() { return s_windowClassName; } static wchar_t* getWindowClassName() { return s_windowClassName; }
/** /**
* Register a mouse click event (should be called * Register a mouse click event (should be called
@@ -351,7 +351,7 @@ protected:
/** ITaskbarList3 structure for progress bar*/ /** ITaskbarList3 structure for progress bar*/
ITaskbarList3 * m_Bar; ITaskbarList3 * m_Bar;
static LPCSTR s_windowClassName; static wchar_t* s_windowClassName;
static const int s_maxTitleLength; static const int s_maxTitleLength;
/** WinTab dll handle */ /** WinTab dll handle */

View File

@@ -0,0 +1,24 @@
set(INC
.
)
set(INC_SYS
${GLEW_INCLUDE_PATH}
)
set(SRC
utfconv.c
utfconv.h
#utf_func.h
)
if(WIN32)
list(APPEND SRC
utf_winfunc.c
utf_winfunc.h
)
endif()
blender_add_lib(bf_intern_utfconv "${SRC}" "${INC}" "${INC_SYS}")

12
intern/utfconv/SConscript Normal file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/python
Import ('env')
sources = env.Glob('*.c')
incs = '.'
defs = ''
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
env.BlenderLib ('bf_utfconv', sources, Split(incs), Split(defs), libtype=['intern','player'], priority=[0,0] )

View File

@@ -0,0 +1,156 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Alexandr Kuznetsov, Andrea Weikert
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifdef WIN32
#ifndef _WIN32_IE
#define _WIN32_IE 0x0501
#endif
#include "utf_winfunc.h"
#include <io.h>
#include <Windows.h>
#include <wchar.h>
FILE * ufopen(const char * filename, const char * mode)
{
FILE * f = NULL;
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 urename(const char *oldname, const char *newname )
{
int r = -1;
UTF16_ENCODE(oldname);
UTF16_ENCODE (newname);
if(oldname_16 && newname_16) r = _wrename(oldname_16, newname_16);
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 = 0;
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;
UTF16_ENCODE(name)
UTF16_ENCODE(value)
if(name_16 && value_16) {
if(SetEnvironmentVariableW(name_16,value_16)!=0)
r =0;
else r = -1;
}
UTF16_UN_ENCODE(value)
UTF16_UN_ENCODE(name)
return r;
}
#endif

View File

@@ -0,0 +1,44 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Alexandr Kuznetsov, Andrea Weikert
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifdef WIN32
#include "utfconv.h"
#include <stdio.h>
FILE * ufopen(const char * filename, const char * mode);
int uopen(const char *filename, int oflag, int pmode);
int urename(const char *oldname, const char *newname );
char * u_alloc_getenv(const char *varname);
void u_free_getenv(char *val);
int uput_getenv(const char *varname, char * value, size_t buffsize);
int uputenv(const char *name, const char *value);
int umkdir(const char *pathname);
#endif

232
intern/utfconv/utfconv.c Normal file
View File

@@ -0,0 +1,232 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Alexandr Kuznetsov, Andrea Weikert
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "utfconv.h"
size_t count_utf_8_from_16(wchar_t * string16)
{
int i;
size_t count = 0;
wchar_t u = 0;
if(!string16) return 0;
for(i=0;u = string16[i];i++)
{
if(u < 0x0080) count+=1; else
if(u < 0x0800) count+=2; else
if(u < 0xD800) count+=3; else
if(u < 0xDC00) {
i++;
if((u = string16[i])==0) break;
if(u >= 0xDC00 && u < 0xE000)count+=4;
} else
if(u < 0xE000) /*illigal*/; else
count+=3;
}
return ++count;
}
size_t count_utf_16_from_8(char * string8)
{
size_t count = 0;
char u;
char type = 0;
unsigned int u32 = 0;
if(!string8) return 0;
for(;(u = *string8);string8++)
{
if(type==0)
{
if((u&0x01<<7) == 0) {count++; u32 = 0; continue;} //1 utf-8 char
if((u&0x07<<5) == 0xC0) {type=1; u32 = u & 0x1F; continue;} //2 utf-8 char
if((u&0x0F<<4) == 0xE0) {type=2; u32 = u & 0x0F; continue;} //3 utf-8 char
if((u&0x1F<<3) == 0xF0) {type=3; u32 = u & 0x07; continue;} //4 utf-8 char
continue;
} else
{
if((u & 0xC0) == 0x80) {u32=(u32<<6) | (u&0x3F); type--;} else
{u32 = 0; type = 0;};
}
if(type==0)
{
if((0 < u32 && u32 < 0xD800) || (0xE000 <= u32 && u32 < 0x10000)) count++; else
if(0x10000 <= u32 && u32 < 0x110000) count+=2;
u32 = 0;
}
}
return ++count;
}
int conv_utf_16_to_8(wchar_t * in16, char * out8, size_t size8)
{
char * out8end = out8+size8;
wchar_t u = 0;
int err = 0;
if(!size8 || !in16 || !out8) return UTF_ERROR_NULL_IN;
out8end--;
for(; out8 < out8end && (u=*in16); in16++, out8++)
{
if(u < 0x0080) *out8 = u; else
if(u < 0x0800) {
if(out8 + 1 >= out8end) break;
*out8++=(0x3<<6) | (0x1F & (u>>6));
*out8 =(0x1<<7) | (0x3F & (u));
}else
if(u < 0xD800 || u >= 0xE000) {
if(out8 + 2 >= out8end) break;
*out8++=(0x7<<5) | (0xF & (u>>12));
*out8++=(0x1<<7) | (0x3F & (u>>6));;
*out8 =(0x1<<7) | (0x3F & (u));
}else
if(u < 0xDC00) {
wchar_t u2 = *++in16;
if(!u2) break;
if(u2 >= 0xDC00 && u2 < 0xE000)
{
if(out8 + 3 >= out8end) break; else {
unsigned int uc = 0x10000 + (u2 - 0xDC00) + ((u - 0xD800)<<10);
*out8++=(0xF<<4) | (0x7 & (uc>>18));
*out8++=(0x1<<7) | (0x3F & (uc>>12));
*out8++=(0x1<<7) | (0x3F & (uc>>6));
*out8 =(0x1<<7) | (0x3F & (uc));
}
} else {out8--; err|=UTF_ERROR_ILLCHAR;};
} else
if(u < 0xE000) {out8--; err|=UTF_ERROR_ILLCHAR;}
}
*out8=*out8end=0;
if(*in16) err|=UTF_ERROR_SMALL;
return err;
}
int conv_utf_8_to_16(char * in8, wchar_t * out16, size_t size16)
{
char u;
char type = 0;
wchar_t u32 = 0;
wchar_t * out16end = out16+size16;
int err = 0;
if(!size16 || !in8 || !out16) return UTF_ERROR_NULL_IN;
out16end--;
for(;out16<out16end && (u = *in8);in8++)
{
if(type==0)
{
if((u&0x01<<7) == 0) {*out16=u; out16++; u32 = 0; continue;} //1 utf-8 char
if((u&0x07<<5) == 0xC0) {type=1; u32 = u & 0x1F; continue;} //2 utf-8 char
if((u&0x0F<<4) == 0xE0) {type=2; u32 = u & 0x0F; continue;} //3 utf-8 char
if((u&0x1F<<3) == 0xF0) {type=3; u32 = u & 0x07; continue;} //4 utf-8 char
err|=UTF_ERROR_ILLCHAR; continue;
} else
{
if((u & 0xC0) == 0x80) {u32=(u32<<6) | (u&0x3F); type--;} else
{u32 = 0; type = 0; err|=UTF_ERROR_ILLSEQ;};
}
if(type==0)
{
if((0 < u32 && u32 < 0xD800) || (0xE000 <= u32 && u32 < 0x10000)) {*out16=u32; out16++;}else
if(0x10000 <= u32 && u32 < 0x110000) {
if(out16 + 1 >= out16end) break;
u32-=0x10000;
*out16 = 0xD800 + (u32 >> 10);
out16++;
*out16 = 0xDC00 + (u32 & 0x3FF);
out16++;
};
u32 = 0;
}
}
*out16=*out16end=0;
if(*in8) err|=UTF_ERROR_SMALL;
return err;
}
int is_ascii(char * in8)
{
for(in8; *in8; in8++)
if(0x80 & *in8) return 0;
return 1;
}
void utf_8_cut_end(char * inout8, size_t maxcutpoint)
{
const char * start = inout8;
char * cur = inout8 + maxcutpoint;
char cc;
if(!inout8) return;
cc = *cur;
}
char * alloc_utf_8_from_16(wchar_t * in16, size_t add)
{
size_t bsize = count_utf_8_from_16(in16);
char * out8 = NULL;
if(!bsize) return NULL;
out8 = (char*)malloc(sizeof(char) * (bsize + add));
conv_utf_16_to_8(in16,out8, bsize);
return out8;
}
wchar_t * alloc_utf16_from_8(char * in8, size_t add)
{
size_t bsize = count_utf_16_from_8(in8);
wchar_t * out16 = NULL;
if(!bsize) return NULL;
out16 =(wchar_t*) malloc(sizeof(wchar_t) * (bsize + add));
conv_utf_8_to_16(in8,out16, bsize);
return out16;
}

102
intern/utfconv/utfconv.h Normal file
View File

@@ -0,0 +1,102 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Alexandr Kuznetsov, Andrea Weikert
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Counts how many bytes is requered for for future utf-8 string using utf-16
* @param string-16 pointer to working utf-16 string
* @return How many bytes must be allocated includeng NULL.
*/
size_t count_utf_8_from_16(wchar_t * string16);
/**
* Counts how many wchar_t (two byte) is requered for for future utf-16 string using utf-8
* @param string-8 pointer to working utf-8 string
* @return How many bytes must be allocated includeng NULL.
*/
size_t count_utf_16_from_8(char * string8);
/**
* conv_utf_*** errors
*/
#define UTF_ERROR_NULL_IN 1<<0 /* Error occures when requered parameter is missing*/
#define UTF_ERROR_ILLCHAR 1<<1 /* Error if character is in illigal UTF rage*/
#define UTF_ERROR_SMALL 1<<2 /* Passed size is to small. It gives legal string with character missing at the end*/
#define UTF_ERROR_ILLSEQ 1<<3 /* Error if sequence is broken and doesn't finish*/
/**
* Converts utf-16 string to allocated utf-8 string
* @params in16 utf-16 string to convert
* @params out8 utf-8 string to string the conversion
* @params size8 the allocated size in bytes of out8
* @return Returns any errors occured during conversion. See the block above,
*/
int conv_utf_16_to_8(wchar_t * in16, char * out8, size_t size8);
/**
* Converts utf-8 string to allocated utf-16 string
* @params in8 utf-8 string to convert
* @params out16 utf-16 string to string the conversion
* @params size16 the allocated size in wchar_t (two byte) of out16
* @return Returns any errors occured during conversion. See the block above,
*/
int conv_utf_8_to_16(char * in8, wchar_t * out16, size_t size16);
/**
* Allocates and converts the utf-8 string from utf-16
* @params in16 utf-16 string to convert
* @params add any additional size which will be allocated for new utf-8 string in bytes
* @return New allocated and converted utf-8 string or NULL if in16 is 0.
*/
char * alloc_utf_8_from_16(wchar_t * in16, size_t add);
/**
* Allocates and converts the utf-16 string from utf-8
* @params in8 utf-8 string to convert
* @params add any additional size which will be allocated for new utf-16 string in wchar_t (two bytes)
* @return New allocated and converted utf-16 string or NULL if in8 is 0.
*/
wchar_t * alloc_utf16_from_8(char * in8, size_t add);
/* Easy allocation and conversion of new utf-16 string. New string has _16 suffix. Must be deallocated with UTF16_UN_ENCODE in right order*/
#define UTF16_ENCODE(in8str) if(1){\
wchar_t * in8str ## _16 = alloc_utf16_from_8((char*)in8str, 0);
#define UTF16_UN_ENCODE(in8str) \
free(in8str ## _16 ); };
#ifdef __cplusplus
}
#endif

View File

@@ -717,7 +717,7 @@ void BKE_undo_save_quit(void)
BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend"); BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666); file = BLI_open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
if(file == -1) { if(file == -1) {
//XXX error("Unable to save %s, check you have permissions", str); //XXX error("Unable to save %s, check you have permissions", str);
return; return;

View File

@@ -279,7 +279,7 @@ int cdf_read_open(CDataFile *cdf, const char *filename)
{ {
FILE *f; FILE *f;
f= fopen(filename, "rb"); f= BLI_fopen(filename, "rb");
if(!f) if(!f)
return 0; return 0;
@@ -350,7 +350,7 @@ int cdf_write_open(CDataFile *cdf, const char *filename)
CDataFileMeshHeader *mesh; CDataFileMeshHeader *mesh;
FILE *f; FILE *f;
f= fopen(filename, "wb"); f= BLI_fopen(filename, "wb");
if(!f) if(!f)
return 0; return 0;

View File

@@ -521,7 +521,7 @@ Image *BKE_add_image_file(const char *name)
BLI_path_abs(str, G.main->name); BLI_path_abs(str, G.main->name);
/* exists? */ /* exists? */
file= open(str, O_BINARY|O_RDONLY); file= BLI_open(str, O_BINARY|O_RDONLY, 0);
if(file== -1) return NULL; if(file== -1) return NULL;
close(file); close(file);

View File

@@ -411,7 +411,7 @@ MovieClip *BKE_add_movieclip_file(const char *name)
BLI_path_abs(str, G.main->name); BLI_path_abs(str, G.main->name);
/* exists? */ /* exists? */
file= open(str, O_BINARY|O_RDONLY); file= BLI_open(str, O_BINARY|O_RDONLY,0);
if(file== -1) return NULL; if(file== -1) return NULL;
close(file); close(file);

View File

@@ -186,7 +186,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
// open the file // open the file
// and create a PackedFile structure // and create a PackedFile structure
file= open(name, O_BINARY|O_RDONLY); file= BLI_open(name, O_BINARY|O_RDONLY,0);
if (file <= 0) { if (file <= 0) {
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path not found: \"%s\"", name); BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path not found: \"%s\"", name);
} else { } else {
@@ -292,7 +292,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i
// make sure the path to the file exists... // make sure the path to the file exists...
BLI_make_existing_file(name); BLI_make_existing_file(name);
file = open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666); file = BLI_open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file >= 0) { if (file >= 0) {
if (write(file, pf->data, pf->size) != pf->size) { if (write(file, pf->data, pf->size) != pf->size) {
BKE_reportf(reports, RPT_ERROR, "Error writing file: %s", name); BKE_reportf(reports, RPT_ERROR, "Error writing file: %s", name);
@@ -347,7 +347,7 @@ int checkPackedFile(const char *filename, PackedFile *pf)
} else { } else {
// we'll have to compare the two... // we'll have to compare the two...
file = open(name, O_BINARY | O_RDONLY); file = BLI_open(name, O_BINARY | O_RDONLY, 0);
if (file < 0) { if (file < 0) {
ret_val = PF_NOFILE; ret_val = PF_NOFILE;
} else { } else {

View File

@@ -4073,7 +4073,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
BLI_path_frame(filename, curFrame, 0); // fixed #frame-no BLI_path_frame(filename, curFrame, 0); // fixed #frame-no
gzf = gzopen(filename, "rb"); gzf = BLI_gzopen(filename, "rb");
if (!gzf) { if (!gzf) {
BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer),"readFsPartData::error - Unable to open file for reading '%s' \n", filename); BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer),"readFsPartData::error - Unable to open file for reading '%s' \n", filename);
// XXX bad level call elbeemDebugOut(debugStrBuffer); // XXX bad level call elbeemDebugOut(debugStrBuffer);

View File

@@ -1144,13 +1144,13 @@ static PTCacheFile *ptcache_file_open(PTCacheID *pid, int mode, int cfra)
if (!BLI_exists(filename)) { if (!BLI_exists(filename)) {
return NULL; return NULL;
} }
fp = fopen(filename, "rb"); fp = BLI_fopen(filename, "rb");
} else if (mode==PTCACHE_FILE_WRITE) { } else if (mode==PTCACHE_FILE_WRITE) {
BLI_make_existing_file(filename); /* will create the dir if needs be, same as //textures is created */ BLI_make_existing_file(filename); /* will create the dir if needs be, same as //textures is created */
fp = fopen(filename, "wb"); fp = BLI_fopen(filename, "wb");
} else if (mode==PTCACHE_FILE_UPDATE) { } else if (mode==PTCACHE_FILE_UPDATE) {
BLI_make_existing_file(filename); BLI_make_existing_file(filename);
fp = fopen(filename, "rb+"); fp = BLI_fopen(filename, "rb+");
} }
if (!fp) if (!fp)

View File

@@ -44,6 +44,7 @@
#include "BLI_string_utf8.h" #include "BLI_string_utf8.h"
#include "BLI_listbase.h" #include "BLI_listbase.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BLI_fileops.h"
#include "DNA_constraint_types.h" #include "DNA_constraint_types.h"
#include "DNA_controller_types.h" #include "DNA_controller_types.h"
@@ -291,7 +292,7 @@ int reopen_text(Text *text)
BLI_strncpy(str, text->name, FILE_MAX); BLI_strncpy(str, text->name, FILE_MAX);
BLI_path_abs(str, G.main->name); BLI_path_abs(str, G.main->name);
fp= fopen(str, "r"); fp= BLI_fopen(str, "r");
if(fp==NULL) return 0; if(fp==NULL) return 0;
/* free memory: */ /* free memory: */
@@ -387,7 +388,7 @@ Text *add_text(const char *file, const char *relpath)
if (relpath) /* can be NULL (bg mode) */ if (relpath) /* can be NULL (bg mode) */
BLI_path_abs(str, relpath); BLI_path_abs(str, relpath);
fp= fopen(str, "r"); fp= BLI_fopen(str, "r");
if(fp==NULL) return NULL; if(fp==NULL) return NULL;
ta= alloc_libblock(&bmain->text, ID_TXT, BLI_path_basename(str)); ta= alloc_libblock(&bmain->text, ID_TXT, BLI_path_basename(str));

View File

@@ -33,6 +33,9 @@
#ifndef __BLI_FILEOPS_H__ #ifndef __BLI_FILEOPS_H__
#define __BLI_FILEOPS_H__ #define __BLI_FILEOPS_H__
#include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@@ -65,6 +68,10 @@ unsigned int BLI_dir_contents(const char *dir, struct direntry **filelist);
/* Files */ /* Files */
FILE * BLI_fopen(const char * filename, const char * mode);
void* BLI_gzopen(const char * filename, const char * mode);
int BLI_open(const char *filename, int oflag, int pmode);
int BLI_file_is_writable(const char *file); int BLI_file_is_writable(const char *file);
int BLI_file_touch(const char *file); int BLI_file_touch(const char *file);

View File

@@ -124,7 +124,7 @@ struct dirent {
typedef struct _DIR { typedef struct _DIR {
HANDLE handle; HANDLE handle;
WIN32_FIND_DATA data; WIN32_FIND_DATAW data;
char path[MAX_PATH]; char path[MAX_PATH];
long dd_loc; long dd_loc;
long dd_size; long dd_size;

View File

@@ -160,4 +160,10 @@ if(WITH_XDG_USER_DIRS)
add_definitions(-DWITH_XDG_USER_DIRS) add_definitions(-DWITH_XDG_USER_DIRS)
endif() endif()
if(WIN32)
list(APPEND INC
../../../intern/utfconv
)
endif()
blender_add_lib(bf_blenlib "${SRC}" "${INC}" "${INC_SYS}") blender_add_lib(bf_blenlib "${SRC}" "${INC}" "${INC_SYS}")

View File

@@ -18,6 +18,7 @@ if env['WITH_BF_BINRELOC']:
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs += ' ' + env['BF_PTHREADS_INC'] incs += ' ' + env['BF_PTHREADS_INC']
incs += ' ../../../intern/utfconv'
if env['OURPLATFORM'] == 'linuxcross': if env['OURPLATFORM'] == 'linuxcross':
if env['WITH_BF_OPENMP']: if env['WITH_BF_OPENMP']:

View File

@@ -44,11 +44,17 @@ struct DynamicLibrary {
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#include "utf_winfunc.h"
#include "utfconv.h"
DynamicLibrary *BLI_dynlib_open(char *name) DynamicLibrary *BLI_dynlib_open(char *name)
{ {
DynamicLibrary *lib; DynamicLibrary *lib;
void *handle= LoadLibrary(name); void *handle;
UTF16_ENCODE(name);
handle= LoadLibraryW(name_16);
UTF16_UN_ENCODE(name);
if(!handle) if(!handle)
return NULL; return NULL;

View File

@@ -45,6 +45,8 @@
#include <io.h> #include <io.h>
#include "BLI_winstuff.h" #include "BLI_winstuff.h"
#include "BLI_callbacks.h" #include "BLI_callbacks.h"
#include "utf_winfunc.h"
#include "utfconv.h"
#else #else
#include <unistd.h> // for read close #include <unistd.h> // for read close
#include <sys/param.h> #include <sys/param.h>
@@ -77,11 +79,10 @@ int BLI_file_gzip(const char *from, const char *to)
/* level 1 is very close to 3 (the default) in terms of file size, /* level 1 is very close to 3 (the default) in terms of file size,
* but about twice as fast, best use for speedy saving - campbell */ * but about twice as fast, best use for speedy saving - campbell */
gzfile = gzopen(to, "wb1"); gzfile = BLI_gzopen(to, "wb1");
if(gzfile == NULL) if(gzfile == NULL)
return -1; return -1;
file = BLI_open(from, O_BINARY|O_RDONLY,0);
file = open(from, O_BINARY|O_RDONLY);
if(file < 0) if(file < 0)
return -2; return -2;
@@ -121,8 +122,7 @@ char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r)
size= 0; size= 0;
gzfile = gzopen( from_file, "rb" ); gzfile = BLI_gzopen( from_file, "rb" );
for(;;) { for(;;) {
if(mem==NULL) { if(mem==NULL) {
mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem"); mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem");
@@ -158,12 +158,12 @@ int BLI_file_is_writable(const char *filename)
int file; int file;
/* first try to open without creating */ /* first try to open without creating */
file = open(filename, O_BINARY | O_RDWR, 0666); file = BLI_open(filename, O_BINARY | O_RDWR, 0666);
if (file < 0) { if (file < 0) {
/* now try to open and create. a test without actually /* now try to open and create. a test without actually
* creating a file would be nice, but how? */ * creating a file would be nice, but how? */
file = open(filename, O_BINARY | O_RDWR | O_CREAT, 0666); file = BLI_open(filename, O_BINARY | O_RDWR | O_CREAT, 0666);
if(file < 0) { if(file < 0) {
return 0; return 0;
@@ -183,13 +183,13 @@ int BLI_file_is_writable(const char *filename)
int BLI_file_touch(const char *file) int BLI_file_touch(const char *file)
{ {
FILE *f = fopen(file,"r+b"); FILE *f = BLI_fopen(file,"r+b");
if (f != NULL) { if (f != NULL) {
char c = getc(f); char c = getc(f);
rewind(f); rewind(f);
putc(c,f); putc(c,f);
} else { } else {
f = fopen(file,"wb"); f = BLI_fopen(file,"wb");
} }
if (f) { if (f) {
fclose(f); fclose(f);
@@ -202,21 +202,63 @@ int BLI_file_touch(const char *file)
static char str[MAXPATHLEN+12]; static char str[MAXPATHLEN+12];
FILE * BLI_fopen(const char * filename, const char * mode)
{
return ufopen(filename, mode);
}
gzFile BLI_gzopen(const char * filename, const char * mode)
{
gzFile gzfile;
int fi;
if(!filename || !mode) {return 0;}
else
{
wchar_t short_name_16 [256];
char short_name [256];
int i=0;
UTF16_ENCODE(filename);
GetShortPathNameW(filename_16,short_name_16,256);
for(i=0;i<256;i++) {short_name[i]=short_name_16[i];};
gzfile = gzopen(short_name,mode);
UTF16_UN_ENCODE(filename);
}
return gzfile;
}
int BLI_open(const char *filename, int oflag, int pmode)
{
return uopen(filename, oflag, pmode);
}
int BLI_delete(const char *file, int dir, int recursive) int BLI_delete(const char *file, int dir, int recursive)
{ {
int err; int err;
UTF16_ENCODE(file)
if (recursive) { if (recursive) {
callLocalErrorCallBack("Recursive delete is unsupported on Windows"); callLocalErrorCallBack("Recursive delete is unsupported on Windows");
err= 1; err= 1;
} else if (dir) { } else if (dir) {
err= !RemoveDirectory(file); err= !RemoveDirectoryW(file_16);
if (err) printf ("Unable to remove directory"); if (err) printf ("Unable to remove directory");
} else { } else {
err= !DeleteFile(file); err= !DeleteFileW(file_16);
if (err) callLocalErrorCallBack("Unable to delete file"); if (err) callLocalErrorCallBack("Unable to delete file");
} }
UTF16_UN_ENCODE(file)
return err; return err;
} }
@@ -235,8 +277,13 @@ int BLI_move(const char *file, const char *to)
strcat(str, BLI_last_slash(file) + 1); strcat(str, BLI_last_slash(file) + 1);
} }
} }
UTF16_ENCODE(file)
UTF16_ENCODE(str)
err= !MoveFileW(file_16, str_16);
UTF16_UN_ENCODE(str)
UTF16_UN_ENCODE(file)
err= !MoveFile(file, str);
if (err) { if (err) {
callLocalErrorCallBack("Unable to move file"); callLocalErrorCallBack("Unable to move file");
printf(" Move from '%s' to '%s' failed\n", file, str); printf(" Move from '%s' to '%s' failed\n", file, str);
@@ -262,8 +309,12 @@ int BLI_copy(const char *file, const char *to)
} }
} }
err= !CopyFile(file,str,FALSE); UTF16_ENCODE(file)
UTF16_ENCODE(str)
err= !CopyFileW(file_16,str_16,FALSE);
UTF16_UN_ENCODE(str)
UTF16_UN_ENCODE(file)
if (err) { if (err) {
callLocalErrorCallBack("Unable to copy file!"); callLocalErrorCallBack("Unable to copy file!");
printf(" Copy from '%s' to '%s' failed\n", file, str); printf(" Copy from '%s' to '%s' failed\n", file, str);
@@ -292,7 +343,7 @@ void BLI_dir_create_recursive(const char *dirname)
BLI_strncpy(tmp, dirname, sizeof(tmp)); BLI_strncpy(tmp, dirname, sizeof(tmp));
lslash= BLI_last_slash(tmp); lslash= BLI_last_slash(tmp);
if (lslash == tmp + strlen(tmp) - 1) { if (lslash == tmp + strlen(tmp) - 1) {
*lslash = 0; *lslash = 0;
} }
@@ -307,8 +358,8 @@ void BLI_dir_create_recursive(const char *dirname)
} }
if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */
if (!CreateDirectory(dirname, NULL)) if (umkdir(dirname)==-1)
callLocalErrorCallBack("Unable to create directory\n"); printf("Unable to create directory %s\n",dirname);
} }
int BLI_rename(const char *from, const char *to) int BLI_rename(const char *from, const char *to)
@@ -318,8 +369,8 @@ int BLI_rename(const char *from, const char *to)
/* make sure the filenames are different (case insensitive) before removing */ /* make sure the filenames are different (case insensitive) before removing */
if (BLI_exists(to) && BLI_strcasecmp(from, to)) if (BLI_exists(to) && BLI_strcasecmp(from, to))
if(BLI_delete(to, 0, 0)) return 1; if(BLI_delete(to, 0, 0)) return 1;
return rename(from, to); return urename(from, to);
} }
#else /* The UNIX world */ #else /* The UNIX world */
@@ -499,6 +550,21 @@ static int delete_single_file(const char *from, const char *UNUSED(to))
return recursiveOp_Callback_OK; return recursiveOp_Callback_OK;
} }
FILE * BLI_fopen(const char * filename, const char * mode)
{
return fopen(filename, mode);
}
gzFile BLI_gzopen(const char * filename, const char * mode)
{
return gzopen(filename, mode);
}
int BLI_open(const char *filename, int oflag, int pmode)
{
return open(filename, oflag, pmode);
}
int BLI_delete(const char *file, int dir, int recursive) int BLI_delete(const char *file, int dir, int recursive)
{ {
if(strchr(file, '"')) { if(strchr(file, '"')) {

View File

@@ -62,6 +62,7 @@
#endif #endif
#ifdef WIN32 #ifdef WIN32
#include "utf_winfunc.h"
# include <io.h> # include <io.h>
# ifdef _WIN32_IE # ifdef _WIN32_IE
# undef _WIN32_IE # undef _WIN32_IE
@@ -825,10 +826,8 @@ const char *BLI_getDefaultDocumentFolder(void)
HRESULT hResult; HRESULT hResult;
/* Check for %HOME% env var */ /* Check for %HOME% env var */
if(uput_getenv("HOME",documentfolder,MAXPATHLEN)) {
ret = getenv("HOME"); if (BLI_is_dir(documentfolder)) return documentfolder;
if(ret) {
if (BLI_is_dir(ret)) return ret;
} }
/* add user profile support for WIN 2K / NT. /* add user profile support for WIN 2K / NT.
@@ -1186,7 +1185,9 @@ void BLI_setenv(const char *env, const char*val)
/* non-free windows */ /* non-free windows */
#elif (defined(WIN32) || defined(WIN64)) /* not free windows */ #elif (defined(WIN32) || defined(WIN64)) /* not free windows */
_putenv_s(env, val); uputenv(env, val);
#else #else
/* linux/osx/bsd */ /* linux/osx/bsd */
setenv(env, val, 1); setenv(env, val, 1);
@@ -1774,17 +1775,23 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
if(GetModuleFileName(0, fullname, maxlen)) { wchar_t * fullname_16 = MEM_mallocN(maxlen*sizeof(wchar_t), "ProgramPath");
if(GetModuleFileNameW(0, fullname_16, maxlen)) {
conv_utf_16_to_8(fullname_16,fullname, maxlen);
if(!BLI_exists(fullname)) { if(!BLI_exists(fullname)) {
printf("path can't be found: \"%.*s\"\n", maxlen, fullname); printf("path can't be found: \"%.*s\"\n", maxlen, fullname);
MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK);
} }
MEM_freeN(fullname_16);
return; return;
} }
MEM_freeN(fullname_16);
#endif #endif
/* unix and non linux */ /* unix and non linux */
if (name && name[0]) { if (name && name[0]) {
BLI_strncpy(fullname, name, maxlen); BLI_strncpy(fullname, name, maxlen);
if (name[0] == '.') { if (name[0] == '.') {
char wdir[FILE_MAX]= ""; char wdir[FILE_MAX]= "";

View File

@@ -78,6 +78,7 @@
#include <io.h> #include <io.h>
#include <direct.h> #include <direct.h>
#include "BLI_winstuff.h" #include "BLI_winstuff.h"
#include "utfconv.h"
#endif #endif
@@ -86,10 +87,13 @@
#include "DNA_listBase.h" #include "DNA_listBase.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h" #include "BLI_listbase.h"
#include "BLI_linklist.h" #include "BLI_linklist.h"
#include "BLI_fileops.h"
#include "BLI_fileops_types.h"
#include "BLI_string.h" #include "BLI_string.h"
#include "BLI_fileops.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
@@ -210,13 +214,22 @@ static void bli_builddir(const char *dirname, const char *relname)
buf[rellen]='/'; buf[rellen]='/';
rellen++; rellen++;
} }
#ifndef WIN32
if (chdir(dirname) == -1) { if (chdir(dirname) == -1) {
perror(dirname); perror(dirname);
return; return;
} }
#else
UTF16_ENCODE(dirname)
if(!SetCurrentDirectoryW(dirname_16)){
perror(dirname);
free(dirname_16);
return;
}
UTF16_UN_ENCODE(dirname)
if ( (dir = (DIR *)opendir(".")) ) { #endif
if ( (dir = (DIR *)opendir(".")) ){
while ((fname = (struct dirent*) readdir(dir)) != NULL) { while ((fname = (struct dirent*) readdir(dir)) != NULL) {
dlink = (struct dirlink *)malloc(sizeof(struct dirlink)); dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
if (dlink) { if (dlink) {
@@ -250,11 +263,16 @@ static void bli_builddir(const char *dirname, const char *relname)
files[actnum].relname = dlink->name; files[actnum].relname = dlink->name;
files[actnum].path = BLI_strdupcat(dirname, dlink->name); files[actnum].path = BLI_strdupcat(dirname, dlink->name);
// use 64 bit file size, only needed for WIN32 and WIN64. // use 64 bit file size, only needed for WIN32 and WIN64.
// Excluding other than current MSVC compiler until able to test. // Excluding other than current MSVC compiler until able to test
#ifdef WIN32
{wchar_t * name_16 = alloc_utf16_from_8(dlink->name,0);
#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER>=1500) #if (defined(WIN32) || defined(WIN64)) && (_MSC_VER>=1500)
_stat64(dlink->name,&files[actnum].s); _wstat64(name_16,&files[actnum].s);
#elif defined(__MINGW32__) #elif defined(__MINGW32__)
_stati64(dlink->name,&files[actnum].s); _stati64(dlink->name,&files[actnum].s);
#endif
free(name_16);};
#else #else
stat(dlink->name,&files[actnum].s); stat(dlink->name,&files[actnum].s);
#endif #endif
@@ -423,13 +441,13 @@ size_t BLI_file_descriptor_size(int file)
struct stat buf; struct stat buf;
if (file <= 0) return (-1); if (file <= 0) return (-1);
fstat(file, &buf); fstat(file, &buf);//CHANGE
return (buf.st_size); return (buf.st_size);
} }
size_t BLI_file_size(const char *path) size_t BLI_file_size(const char *path)
{ {
int size, file = open(path, O_BINARY|O_RDONLY); int size, file = BLI_open(path, O_BINARY|O_RDONLY, 0);
if (file == -1) if (file == -1)
return -1; return -1;
@@ -442,27 +460,26 @@ size_t BLI_file_size(const char *path)
int BLI_exists(const char *name) int BLI_exists(const char *name)
{ {
#if defined(WIN32) && !defined(__MINGW32__) #if defined(WIN32)
#ifndef __MINGW32__
struct _stat64i32 st; struct _stat64i32 st;
/* in Windows stat doesn't recognize dir ending on a slash #else
* To not break code where the ending slash is expected we
* don't mess with the argument name directly here - elubie */
char tmp[FILE_MAX];
int len, res;
BLI_strncpy(tmp, name, FILE_MAX);
len = strlen(tmp);
if (len > 3 && ( tmp[len-1]=='\\' || tmp[len-1]=='/') ) tmp[len-1] = '\0';
res = _stat(tmp, &st);
if (res == -1) return(0);
#elif defined(__MINGW32__)
struct _stati64 st; struct _stati64 st;
char tmp[FILE_MAX]; #endif
/* in Windows stat doesn't recognize dir ending on a slash
To not break code where the ending slash is expected we
don't mess with the argument name directly here - elubie */
wchar_t * tmp_16 = alloc_utf16_from_8(name, 0);
int len, res; int len, res;
BLI_strncpy(tmp, name, FILE_MAX); len = wcslen(tmp_16);
len = strlen(tmp); if (len > 3 && ( tmp_16[len-1]==L'\\' || tmp_16[len-1]==L'/') ) tmp_16[len-1] = '\0';
if (len > 3 && ( tmp[len-1]=='\\' || tmp[len-1]=='/') ) tmp[len-1] = '\0'; #ifndef __MINGW32__
res = _stati64(tmp, &st); res = _wstat(tmp_16, &st);
if (res) return(0); #else
res = _wstati64(tmp_16, &st);
#endif
free(tmp_16);
if (res == -1) return(0);
#else #else
struct stat st; struct stat st;
if (stat(name,&st)) return(0); if (stat(name,&st)) return(0);
@@ -484,7 +501,7 @@ int BLI_is_file(const char *path)
LinkNode *BLI_file_read_as_lines(const char *name) LinkNode *BLI_file_read_as_lines(const char *name)
{ {
FILE *fp= fopen(name, "r"); FILE *fp= BLI_fopen(name, "r");
LinkNode *lines= NULL; LinkNode *lines= NULL;
char *buf; char *buf;
size_t size; size_t size;
@@ -530,11 +547,23 @@ void BLI_file_free_lines(LinkNode *lines)
int BLI_file_older(const char *file1, const char *file2) int BLI_file_older(const char *file1, const char *file2)
{ {
#if WIN32
struct _stat st1, st2;
UTF16_ENCODE(file1)
UTF16_ENCODE(file2)
if(_wstat(file1_16, &st1)) return 0;
if(_wstat(file2_16, &st2)) return 0;
UTF16_UN_ENCODE(file2)
UTF16_UN_ENCODE(file1)
#else
struct stat st1, st2; struct stat st1, st2;
if(stat(file1, &st1)) return 0; if(stat(file1, &st1)) return 0;
if(stat(file2, &st2)) return 0; if(stat(file2, &st2)) return 0;
#endif
return (st1.st_mtime < st2.st_mtime); return (st1.st_mtime < st2.st_mtime);
} }

View File

@@ -47,13 +47,16 @@
#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY #define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY
#include "BLI_winstuff.h" #include "BLI_winstuff.h"
/* FILE_MAX */ #include "utf_winfunc.h"
#include "utfconv.h"
/* FILE_MAXDIR + FILE_MAXFILE */
int BLI_getInstallationDir( char * str ) int BLI_getInstallationDir( char * str )
{ {
char dir[FILE_MAXDIR]; char dir[FILE_MAXDIR];
int a; int a;
/*change to utf support*/
GetModuleFileName(NULL,str,FILE_MAX); GetModuleFileName(NULL,str,FILE_MAX);
BLI_split_dir_part(str, dir, sizeof(dir)); /* shouldn't be relative */ BLI_split_dir_part(str, dir, sizeof(dir)); /* shouldn't be relative */
a = strlen(dir); a = strlen(dir);
@@ -169,7 +172,9 @@ void RegisterBlendExtension(void)
DIR *opendir (const char *path) DIR *opendir (const char *path)
{ {
if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) { wchar_t * path_16 = alloc_utf16_from_8(path, 0);
if (GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) {
DIR *newd= MEM_mallocN(sizeof(DIR), "opendir"); DIR *newd= MEM_mallocN(sizeof(DIR), "opendir");
newd->handle = INVALID_HANDLE_VALUE; newd->handle = INVALID_HANDLE_VALUE;
@@ -180,29 +185,56 @@ DIR *opendir (const char *path)
newd->direntry.d_reclen= 0; newd->direntry.d_reclen= 0;
newd->direntry.d_name= NULL; newd->direntry.d_name= NULL;
free(path_16);
return newd; return newd;
} else { } else {
free(path_16);
return NULL; return NULL;
} }
} }
struct dirent *readdir(DIR *dp) static char * BLI_alloc_utf_8_from_16(wchar_t * in16, size_t add)
{ {
size_t bsize = count_utf_8_from_16(in16);
char * out8 = NULL;
if(!bsize) return NULL;
out8 = (char*)MEM_mallocN(sizeof(char) * (bsize + add),"UTF-8 String");
conv_utf_16_to_8(in16,out8, bsize);
return out8;
}
static wchar_t * BLI_alloc_utf16_from_8(char * in8, size_t add)
{
size_t bsize = count_utf_16_from_8(in8);
wchar_t * out16 = NULL;
if(!bsize) return NULL;
out16 =(wchar_t*) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String");
conv_utf_8_to_16(in8,out16, bsize);
return out16;
}
struct dirent *readdir(DIR *dp) {
char * FileName;
size_t size;
if (dp->direntry.d_name) { if (dp->direntry.d_name) {
MEM_freeN(dp->direntry.d_name); MEM_freeN(dp->direntry.d_name);
dp->direntry.d_name= NULL; dp->direntry.d_name= NULL;
} }
if (dp->handle==INVALID_HANDLE_VALUE) { if (dp->handle==INVALID_HANDLE_VALUE) {
dp->handle= FindFirstFile(dp->path, &(dp->data)); wchar_t * path_16 = alloc_utf16_from_8(dp->path, 0);
dp->handle= FindFirstFileW(path_16, &(dp->data));
free(path_16);
if (dp->handle==INVALID_HANDLE_VALUE) if (dp->handle==INVALID_HANDLE_VALUE)
return NULL; return NULL;
dp->direntry.d_name= BLI_strdup(dp->data.cFileName); dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName, 0);
return &dp->direntry; return &dp->direntry;
} else if (FindNextFile (dp->handle, &(dp->data))) { } else if (FindNextFileW (dp->handle, &(dp->data))) {
dp->direntry.d_name= BLI_strdup(dp->data.cFileName); dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName,0);
return &dp->direntry; return &dp->direntry;
} else { } else {

View File

@@ -990,7 +990,7 @@ FileData *blo_openblenderfile(const char *filepath, ReportList *reports)
{ {
gzFile gzfile; gzFile gzfile;
errno= 0; errno= 0;
gzfile= gzopen(filepath, "rb"); gzfile= BLI_gzopen(filepath, "rb");
if (gzfile == (gzFile)Z_NULL) { if (gzfile == (gzFile)Z_NULL) {
BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error reading file"); BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error reading file");

View File

@@ -68,7 +68,7 @@ static int handle_read_msb_int(int handle)
int BLO_is_a_runtime(const char *path) int BLO_is_a_runtime(const char *path)
{ {
int res= 0, fd= open(path, O_BINARY|O_RDONLY, 0); int res= 0, fd= BLI_open(path, O_BINARY|O_RDONLY, 0);
int datastart; int datastart;
char buf[8]; char buf[8];
@@ -102,7 +102,7 @@ BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
int fd, datastart; int fd, datastart;
char buf[8]; char buf[8];
fd= open(path, O_BINARY|O_RDONLY, 0); fd= BLI_open(path, O_BINARY|O_RDONLY, 0);
if(fd==-1) { if(fd==-1) {
BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", path, strerror(errno)); BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", path, strerror(errno));

View File

@@ -2887,7 +2887,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
/* open temporary file, so we preserve the original in case we crash */ /* open temporary file, so we preserve the original in case we crash */
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath); BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
file = open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666); file = BLI_open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
if(file == -1) { if(file == -1) {
BKE_reportf(reports, RPT_ERROR, "Can't open file %s for writing: %s.", tempname, strerror(errno)); BKE_reportf(reports, RPT_ERROR, "Can't open file %s for writing: %s.", tempname, strerror(errno));
return 0; return 0;

View File

@@ -2051,7 +2051,7 @@ void REEB_exportGraph(ReebGraph *rg, int count)
else { else {
sprintf(filename, "test%05i.txt", count); sprintf(filename, "test%05i.txt", count);
} }
f = fopen(filename, "w"); f = BLI_fopen(filename, "w");
for(arc = rg->arcs.first; arc; arc = arc->next) for(arc = rg->arcs.first; arc; arc = arc->next)
{ {

View File

@@ -348,7 +348,7 @@ static int paste_file(bContext *C, ReportList *reports, const char *filename)
int filelen; int filelen;
char *strp; char *strp;
fp= fopen(filename, "r"); fp= BLI_fopen(filename, "r");
if(!fp) { if(!fp) {
if(reports) if(reports)

View File

@@ -684,7 +684,7 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF
// check selected directory // check selected directory
// simply try to open cfg file for writing to test validity of settings // simply try to open cfg file for writing to test validity of settings
fileCfg = fopen(targetFile, "w"); fileCfg = BLI_fopen(targetFile, "w");
if(fileCfg) { if(fileCfg) {
dirExist = 1; fclose(fileCfg); dirExist = 1; fclose(fileCfg);
// remove cfg dummy from directory test // remove cfg dummy from directory test

View File

@@ -233,7 +233,7 @@ void fsmenu_write_file(struct FSMenu* fsmenu, const char *filename)
FSMenuEntry *fsme= NULL; FSMenuEntry *fsme= NULL;
int nskip= 0; int nskip= 0;
FILE *fp = fopen(filename, "w"); FILE *fp = BLI_fopen(filename, "w");
if (!fp) return; if (!fp) return;
fprintf(fp, "[Bookmarks]\n"); fprintf(fp, "[Bookmarks]\n");
@@ -262,7 +262,7 @@ void fsmenu_read_bookmarks(struct FSMenu* fsmenu, const char *filename)
FSMenuCategory category = FS_CATEGORY_BOOKMARKS; FSMenuCategory category = FS_CATEGORY_BOOKMARKS;
FILE *fp; FILE *fp;
fp = fopen(filename, "r"); fp = BLI_fopen(filename, "r");
if (!fp) return; if (!fp) return;
while ( fgets ( line, 256, fp ) != NULL ) /* read a line */ while ( fgets ( line, 256, fp ) != NULL ) /* read a line */

View File

@@ -460,7 +460,7 @@ static void txt_write_file(Text *text, ReportList *reports)
BLI_strncpy(filepath, text->name, FILE_MAX); BLI_strncpy(filepath, text->name, FILE_MAX);
BLI_path_abs(filepath, G.main->name); BLI_path_abs(filepath, G.main->name);
fp= fopen(filepath, "w"); fp= BLI_fopen(filepath, "w");
if(fp==NULL) { if(fp==NULL) {
BKE_reportf(reports, RPT_ERROR, "Unable to save \"%s\": %s", filepath, errno ? strerror(errno) : "Unknown error writing file"); BKE_reportf(reports, RPT_ERROR, "Unable to save \"%s\": %s", filepath, errno ? strerror(errno) : "Unknown error writing file");
return; return;

View File

@@ -180,4 +180,10 @@ if(WITH_IMAGE_HDR)
add_definitions(-DWITH_HDR) add_definitions(-DWITH_HDR)
endif() endif()
if(WIN32)
list(APPEND INC
../../../intern/utfconv
)
endif()
blender_add_lib(bf_imbuf "${SRC}" "${INC}" "${INC_SYS}") blender_add_lib(bf_imbuf "${SRC}" "${INC}" "${INC_SYS}")

View File

@@ -17,6 +17,7 @@ defs = []
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs += ' ' + env['BF_PTHREADS_INC'] incs += ' ' + env['BF_PTHREADS_INC']
incs += ' ../../../intern/utfconv'
if env['WITH_BF_OPENEXR']: if env['WITH_BF_OPENEXR']:
defs.append('WITH_OPENEXR') defs.append('WITH_OPENEXR')

View File

@@ -216,7 +216,7 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags)
bytesize = (ibuf->x * 3 + extrabytes) * ibuf->y; bytesize = (ibuf->x * 3 + extrabytes) * ibuf->y;
data = (uchar *) ibuf->rect; data = (uchar *) ibuf->rect;
ofile = fopen(name,"wb"); ofile = BLI_fopen(name,"wb");
if (!ofile) return 0; if (!ofile) return 0;
putShortLSB(19778,ofile); /* "BM" */ putShortLSB(19778,ofile); /* "BM" */

View File

@@ -38,6 +38,7 @@
#include <string.h> /* memset */ #include <string.h> /* memset */
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BLI_fileops.h"
#include "cin_debug_stuff.h" #include "cin_debug_stuff.h"
#include "logmemfile.h" #include "logmemfile.h"
@@ -523,7 +524,7 @@ cineonOpen(const char* filename) {
cineon->memcursor = 0; cineon->memcursor = 0;
cineon->membuffersize = 0; cineon->membuffersize = 0;
cineon->file = fopen(filename, "rb"); cineon->file = BLI_fopen(filename, "rb");
if (cineon->file == 0) { if (cineon->file == 0) {
if (verbose) d_printf("Failed to open file \"%s\".\n", filename); if (verbose) d_printf("Failed to open file \"%s\".\n", filename);
cineonClose(cineon); cineonClose(cineon);
@@ -727,7 +728,7 @@ cineonCreate(const char* filename, int width, int height, int depth) {
cineon->lineBuffer = 0; cineon->lineBuffer = 0;
cineon->pixelBuffer = 0; cineon->pixelBuffer = 0;
cineon->file = fopen(filename, "wb"); cineon->file = BLI_fopen(filename, "wb");
if (cineon->file == 0) { if (cineon->file == 0) {
if (verbose) d_printf("Couldn't open file %s\n", filename); if (verbose) d_printf("Couldn't open file %s\n", filename);
cineonClose(cineon); cineonClose(cineon);

View File

@@ -38,6 +38,7 @@
#include <string.h> /* memset */ #include <string.h> /* memset */
#include "cin_debug_stuff.h" #include "cin_debug_stuff.h"
#include "logmemfile.h" #include "logmemfile.h"
#include "BLI_fileops.h"
static void static void
fillDpxChannelInfo(DpxFile* dpx, DpxChannelInformation* chan, int des) { fillDpxChannelInfo(DpxFile* dpx, DpxChannelInformation* chan, int des) {
@@ -401,7 +402,7 @@ intern_dpxOpen(int mode, const char* bytestuff, int bufsize) {
if (mode == LFREALFILE) { if (mode == LFREALFILE) {
filename = bytestuff; filename = bytestuff;
dpx->file = fopen(filename, "rb"); dpx->file = BLI_fopen(filename, "rb");
if (dpx->file == 0) { if (dpx->file == 0) {
if (verbose) d_printf("Failed to open file \"%s\".\n", filename); if (verbose) d_printf("Failed to open file \"%s\".\n", filename);
dpxClose(dpx); dpxClose(dpx);
@@ -589,7 +590,7 @@ dpxCreate(const char* filename, int width, int height, int depth) {
dpx->lineBuffer = 0; dpx->lineBuffer = 0;
dpx->pixelBuffer = 0; dpx->pixelBuffer = 0;
dpx->file = fopen(filename, "wb"); dpx->file = BLI_fopen(filename, "wb");
if (dpx->file == 0) { if (dpx->file == 0) {
if (verbose) d_printf("Couldn't open file %s\n", filename); if (verbose) d_printf("Couldn't open file %s\n", filename);
dpxClose(dpx); dpxClose(dpx);
@@ -687,7 +688,7 @@ dpxDump(const char* filename) {
DpxMainHeader header; DpxMainHeader header;
FILE* file; FILE* file;
file = fopen(filename, "rb"); file = BLI_fopen(filename, "rb");
if (file == 0) { if (file == 0) {
d_printf("Failed to open file \"%s\".\n", filename); d_printf("Failed to open file \"%s\".\n", filename);
return; return;

View File

@@ -36,6 +36,7 @@
#include <netinet/in.h> /* htonl() */ #include <netinet/in.h> /* htonl() */
#endif #endif
#include <string.h> /* memset */ #include <string.h> /* memset */
#include "BLI_fileops.h"
#define MIN_GAMMA 0.01 #define MIN_GAMMA 0.01
#define MAX_GAMMA 99.9 #define MAX_GAMMA 99.9
@@ -154,7 +155,7 @@ logImageDump(const char* filename)
U32 magic; U32 magic;
FILE* foo = fopen(filename, "rb"); FILE* foo = BLI_fopen(filename, "rb");
if (foo == 0) { if (foo == 0) {
return; return;
} }

View File

@@ -81,7 +81,7 @@ anim_index_builder * IMB_index_builder_create(const char * name)
BLI_make_existing_file(rv->temp_name); BLI_make_existing_file(rv->temp_name);
rv->fp = fopen(rv->temp_name, "wb"); rv->fp = BLI_fopen(rv->temp_name, "wb");
if (!rv->fp) { if (!rv->fp) {
fprintf(stderr, "Couldn't open index target: %s! " fprintf(stderr, "Couldn't open index target: %s! "
@@ -140,7 +140,7 @@ void IMB_index_builder_finish(anim_index_builder * fp, int rollback)
unlink(fp->temp_name); unlink(fp->temp_name);
} else { } else {
unlink(fp->name); unlink(fp->name);
rename(fp->temp_name, fp->name); BLI_rename(fp->temp_name, fp->name);
} }
MEM_freeN(fp); MEM_freeN(fp);
@@ -150,7 +150,7 @@ struct anim_index * IMB_indexer_open(const char * name)
{ {
char header[13]; char header[13];
struct anim_index * idx; struct anim_index * idx;
FILE * fp = fopen(name, "rb"); FILE * fp = BLI_fopen(name, "rb");
int i; int i;
if (!fp) { if (!fp) {
@@ -690,7 +690,7 @@ static void free_proxy_output_ffmpeg(struct proxy_output_ctx * ctx,
get_proxy_filename(ctx->anim, ctx->proxy_size, get_proxy_filename(ctx->anim, ctx->proxy_size,
fname, FALSE); fname, FALSE);
unlink(fname); unlink(fname);
rename(fname_tmp, fname); BLI_rename(fname_tmp, fname);
} }
MEM_freeN(ctx); MEM_freeN(ctx);

View File

@@ -674,7 +674,7 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons
int rlebuflen, goodwrite; int rlebuflen, goodwrite;
goodwrite = 1; goodwrite = 1;
outf = fopen(name, "wb"); outf = BLI_fopen(name, "wb");
if(!outf) return 0; if(!outf) return 0;
tablen = ysize*zsize*sizeof(int); tablen = ysize*zsize*sizeof(int);

View File

@@ -731,7 +731,7 @@ int imb_savejp2(struct ImBuf *ibuf, const char *name, int flags)
codestream_length = cio_tell(cio); codestream_length = cio_tell(cio);
/* write the buffer to disk */ /* write the buffer to disk */
f = fopen(name, "wb"); f = BLI_fopen(name, "wb");
if (!f) { if (!f) {
fprintf(stderr, "failed to open %s for writing\n", name); fprintf(stderr, "failed to open %s for writing\n", name);

View File

@@ -608,7 +608,7 @@ static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr; struct my_error_mgr jerr;
if ((outfile = fopen(name, "wb")) == NULL) return 0; if ((outfile = BLI_fopen(name, "wb")) == NULL) return 0;
jpeg_default_quality = 75; jpeg_default_quality = 75;
cinfo->err = jpeg_std_error(&jerr.pub); cinfo->err = jpeg_std_error(&jerr.pub);
@@ -642,7 +642,7 @@ static int save_vidjpeg(const char *name, struct ImBuf *ibuf)
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr; struct my_error_mgr jerr;
if ((outfile = fopen(name, "wb")) == NULL) return 0; if ((outfile = BLI_fopen(name, "wb")) == NULL) return 0;
jpeg_default_quality = 90; jpeg_default_quality = 90;
cinfo->err = jpeg_std_error(&jerr.pub); cinfo->err = jpeg_std_error(&jerr.pub);
@@ -712,7 +712,7 @@ static int save_maxjpeg(const char *name, struct ImBuf *ibuf)
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr; struct my_error_mgr jerr;
if ((outfile = fopen(name, "wb")) == NULL) return 0; if ((outfile = BLI_fopen(name, "wb")) == NULL) return 0;
jpeg_default_quality = 100; jpeg_default_quality = 100;
cinfo->err = jpeg_std_error(&jerr.pub); cinfo->err = jpeg_std_error(&jerr.pub);

View File

@@ -195,7 +195,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
Flush); Flush);
} }
else { else {
fp = fopen(name, "wb"); fp = BLI_fopen(name, "wb");
if (!fp) { if (!fp) {
png_destroy_write_struct(&png_ptr, &info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr);
MEM_freeN(pixels); MEM_freeN(pixels);

View File

@@ -332,7 +332,7 @@ static void writeHeader(FILE *file, int width, int height)
int imb_savehdr(struct ImBuf *ibuf, const char *name, int flags) int imb_savehdr(struct ImBuf *ibuf, const char *name, int flags)
{ {
FILE* file = fopen(name, "wb"); FILE* file = BLI_fopen(name, "wb");
float *fp= NULL; float *fp= NULL;
int y, width=ibuf->x, height=ibuf->y; int y, width=ibuf->x, height=ibuf->y;
unsigned char *cp= NULL; unsigned char *cp= NULL;

View File

@@ -126,7 +126,7 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags)
imb_cache_filename(filepath_tx, filepath, flags); imb_cache_filename(filepath_tx, filepath, flags);
file = open(filepath_tx, O_BINARY|O_RDONLY); file = BLI_open(filepath_tx, O_BINARY|O_RDONLY, 0);
if(file < 0) return NULL; if(file < 0) return NULL;
ibuf= IMB_loadifffile(file, flags, filepath_tx); ibuf= IMB_loadifffile(file, flags, filepath_tx);
@@ -152,7 +152,7 @@ ImBuf *IMB_testiffname(const char *filepath, int flags)
imb_cache_filename(filepath_tx, filepath, flags); imb_cache_filename(filepath_tx, filepath, flags);
file = open(filepath_tx,O_BINARY|O_RDONLY); file = BLI_open(filepath_tx,O_BINARY|O_RDONLY,0);
if(file < 0) return NULL; if(file < 0) return NULL;
ibuf=IMB_loadifffile(file, flags|IB_test|IB_multilayer, filepath_tx); ibuf=IMB_loadifffile(file, flags|IB_test|IB_multilayer, filepath_tx);
@@ -195,7 +195,7 @@ void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
{ {
int file; int file;
file = open(ibuf->cachename, O_BINARY|O_RDONLY); file = BLI_open(ibuf->cachename, O_BINARY|O_RDONLY, 0);
if(file < 0) return; if(file < 0) return;
imb_loadtilefile(ibuf, file, tx, ty, rect); imb_loadtilefile(ibuf, file, tx, ty, rect);

View File

@@ -268,7 +268,7 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
if (ibuf->planes==32) { if (ibuf->planes==32) {
buf[17] |= 0x08; buf[17] |= 0x08;
} }
fildes = fopen(name,"wb"); fildes = BLI_fopen(name,"wb");
if (!fildes) return 0; if (!fildes) return 0;
if (fwrite(buf, 1, 18,fildes) != 18) { if (fwrite(buf, 1, 18,fildes) != 18) {

View File

@@ -61,6 +61,7 @@
#include <process.h> /* getpid */ #include <process.h> /* getpid */
#include <direct.h> /* chdir */ #include <direct.h> /* chdir */
#include "BLI_winstuff.h" #include "BLI_winstuff.h"
#include "utfconv.h"
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif
@@ -70,8 +71,12 @@
static int get_thumb_dir( char* dir , ThumbSize size) static int get_thumb_dir( char* dir , ThumbSize size)
{ {
#ifdef WIN32 #ifdef WIN32
wchar_t dir_16 [MAX_PATH];
/* yes, applications shouldn't store data there, but so does GIMP :)*/ /* yes, applications shouldn't store data there, but so does GIMP :)*/
SHGetSpecialFolderPath(0, dir, CSIDL_PROFILE, 0); SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0);
conv_utf_16_to_8(dir_16,dir,FILE_MAX);
#else #else
const char* home = getenv("HOME"); const char* home = getenv("HOME");
if (!home) return 0; if (!home) return 0;

View File

@@ -30,6 +30,7 @@
#include "zlib.h" #include "zlib.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BLI_fileops.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
#include "BKE_global.h" #include "BKE_global.h"
@@ -123,9 +124,8 @@ static ImBuf *loadblend_thumb(gzFile gzfile)
ImBuf *IMB_loadblend_thumb(const char *path) ImBuf *IMB_loadblend_thumb(const char *path)
{ {
gzFile gzfile; gzFile gzfile;
/* not necessarily a gzip */ /* not necessarily a gzip */
gzfile = gzopen(path, "rb"); gzfile = BLI_gzopen(path, "rb");
if (NULL == gzfile ) { if (NULL == gzfile ) {
return NULL; return NULL;

View File

@@ -159,7 +159,7 @@ static int IMB_ispic_name(const char *name)
if(((st.st_mode) & S_IFMT) != S_IFREG) if(((st.st_mode) & S_IFMT) != S_IFREG)
return FALSE; return FALSE;
if((fp = open(name,O_BINARY|O_RDONLY)) < 0) if((fp = BLI_open(name,O_BINARY|O_RDONLY, 0)) < 0)
return FALSE; return FALSE;
if(read(fp, buf, 32) != 32) { if(read(fp, buf, 32) != 32) {

View File

@@ -184,7 +184,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
// ------------------------------------------------ // ------------------------------------------------
// get numverts + numfaces first // get numverts + numfaces first
// ------------------------------------------------ // ------------------------------------------------
gzf = gzopen(filename, "rb"); gzf = BLI_gzopen(filename, "rb");
if (!gzf) if (!gzf)
{ {
return NULL; return NULL;
@@ -216,7 +216,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
if(!numfaces || !numverts || !gotBytes) if(!numfaces || !numverts || !gotBytes)
return NULL; return NULL;
gzf = gzopen(filename, "rb"); gzf = BLI_gzopen(filename, "rb");
if (!gzf) if (!gzf)
{ {
return NULL; return NULL;
@@ -409,7 +409,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *
filename[len-5] = 'e'; filename[len-5] = 'e';
filename[len-4] = 'l'; filename[len-4] = 'l';
gzf = gzopen(filename, "rb"); gzf = BLI_gzopen(filename, "rb");
if (!gzf) if (!gzf)
{ {
MEM_freeN(fss->meshVelocities); MEM_freeN(fss->meshVelocities);

View File

@@ -52,6 +52,7 @@
#include "DNA_text_types.h" #include "DNA_text_types.h"
#include "BLI_path_util.h" #include "BLI_path_util.h"
#include "BLI_fileops.h"
#include "BLI_math_base.h" #include "BLI_math_base.h"
#include "BLI_string.h" #include "BLI_string.h"
#include "BLI_string_utf8.h" #include "BLI_string_utf8.h"
@@ -388,7 +389,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
} }
else { else {
FILE *fp = fopen(fn, "r"); FILE *fp = BLI_fopen(fn, "r");
if (fp) { if (fp) {
py_dict = PyC_DefaultNameSpace(fn); py_dict = PyC_DefaultNameSpace(fn);

View File

@@ -342,7 +342,7 @@ void cache_voxeldata(Tex *tex, int scene_frame)
case TEX_VD_BLENDERVOXEL: case TEX_VD_BLENDERVOXEL:
BLI_path_abs(path, G.main->name); BLI_path_abs(path, G.main->name);
if (!BLI_exists(path)) return; if (!BLI_exists(path)) return;
fp = fopen(path,"rb"); fp = BLI_fopen(path,"rb");
if (!fp) return; if (!fp) return;
if(read_voxeldata_header(fp, vd)) if(read_voxeldata_header(fp, vd))
@@ -353,7 +353,7 @@ void cache_voxeldata(Tex *tex, int scene_frame)
case TEX_VD_RAW_8BIT: case TEX_VD_RAW_8BIT:
BLI_path_abs(path, G.main->name); BLI_path_abs(path, G.main->name);
if (!BLI_exists(path)) return; if (!BLI_exists(path)) return;
fp = fopen(path,"rb"); fp = BLI_fopen(path,"rb");
if (!fp) return; if (!fp) return;
load_frame_raw8(vd, fp, curframe); load_frame_raw8(vd, fp, curframe);

View File

@@ -136,4 +136,10 @@ if(WITH_BUILDINFO)
add_definitions(-DWITH_BUILDINFO) add_definitions(-DWITH_BUILDINFO)
endif() endif()
if(WIN322)
list(APPEND INC
../../../intern/utfconv
)
endif()
blender_add_lib_nolist(bf_windowmanager "${SRC}" "${INC}" "${INC_SYS}") blender_add_lib_nolist(bf_windowmanager "${SRC}" "${INC}" "${INC_SYS}")

View File

@@ -32,6 +32,7 @@ if env['OURPLATFORM'] == 'linux':
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs += ' ' + env['BF_PTHREADS_INC'] incs += ' ' + env['BF_PTHREADS_INC']
incs += ' ../../intern/utfconv'
if env['OURPLATFORM'] != 'darwin' or env['WITH_GHOST_COCOA']: if env['OURPLATFORM'] != 'darwin' or env['WITH_GHOST_COCOA']:
sources.remove('intern' + os.sep + 'wm_apple.c') sources.remove('intern' + os.sep + 'wm_apple.c')

View File

@@ -304,6 +304,7 @@ static void wm_init_userdef(bContext *C)
#define BKE_READ_EXOTIC_OK_BLEND 0 /* .blend file */ #define BKE_READ_EXOTIC_OK_BLEND 0 /* .blend file */
#define BKE_READ_EXOTIC_OK_OTHER 1 /* other supported formats */ #define BKE_READ_EXOTIC_OK_OTHER 1 /* other supported formats */
/* intended to check for non-blender formats but for now it only reads blends */ /* intended to check for non-blender formats but for now it only reads blends */
static int wm_read_exotic(Scene *UNUSED(scene), const char *name) static int wm_read_exotic(Scene *UNUSED(scene), const char *name)
{ {
@@ -319,8 +320,7 @@ static int wm_read_exotic(Scene *UNUSED(scene), const char *name)
retval= BKE_READ_EXOTIC_FAIL_PATH; retval= BKE_READ_EXOTIC_FAIL_PATH;
} }
else { else {
gzfile = gzopen(name,"rb"); gzfile = BLI_gzopen(name,"rb");
if (gzfile == NULL) { if (gzfile == NULL) {
retval= BKE_READ_EXOTIC_FAIL_OPEN; retval= BKE_READ_EXOTIC_FAIL_OPEN;
} }
@@ -627,7 +627,7 @@ static void write_history(void)
recent = G.recent_files.first; recent = G.recent_files.first;
/* refresh recent-files.txt of recent opened files, when current file was changed */ /* refresh recent-files.txt of recent opened files, when current file was changed */
if(!(recent) || (BLI_path_cmp(recent->filepath, G.main->name)!=0)) { if(!(recent) || (BLI_path_cmp(recent->filepath, G.main->name)!=0)) {
fp= fopen(name, "w"); fp= BLI_fopen(name, "w");
if (fp) { if (fp) {
/* add current file to the beginning of list */ /* add current file to the beginning of list */
recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile"); recent = (RecentFile*)MEM_mallocN(sizeof(RecentFile),"RecentFile");

View File

@@ -40,6 +40,10 @@ blender_include_dirs(
../blender/windowmanager ../blender/windowmanager
) )
if(WIN32)
blender_include_dirs(../../intern/utfconv)
endif()
if(WITH_LIBMV) if(WITH_LIBMV)
blender_include_dirs(../../extern/libmv) blender_include_dirs(../../extern/libmv)
add_definitions(-DWITH_LIBMV) add_definitions(-DWITH_LIBMV)
@@ -823,6 +827,7 @@ endif()
bf_intern_memutil bf_intern_memutil
bf_intern_guardedalloc bf_intern_guardedalloc
bf_intern_ctr bf_intern_ctr
bf_intern_utfconv
ge_blen_routines ge_blen_routines
ge_converter ge_converter
ge_phys_dummy ge_phys_dummy

View File

@@ -40,6 +40,11 @@
#include <xmmintrin.h> #include <xmmintrin.h>
#endif #endif
#ifdef WIN32
#include <Windows.h>
#include "utfconv.h"
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
@@ -1109,12 +1114,28 @@ char **environ = NULL;
#endif #endif
#ifdef WIN32
int main(int argc, const char **argv_c) /*Do not mess with const*/
#else
int main(int argc, const char **argv) int main(int argc, const char **argv)
#endif
{ {
SYS_SystemHandle syshandle; SYS_SystemHandle syshandle;
bContext *C= CTX_create(); bContext *C= CTX_create();
bArgs *ba; bArgs *ba;
#ifdef WIN32
wchar_t ** argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
int argci = 0;
char ** argv = MEM_mallocN(argc * sizeof(char*),"argv array");
for(argci=0; argci<argc; argci++)
{
argv[argci] = alloc_utf_8_from_16(argv_16[argci],0);
}
LocalFree(argv_16);
#endif
#ifdef WITH_PYTHON_MODULE #ifdef WITH_PYTHON_MODULE
#ifdef __APPLE__ #ifdef __APPLE__
environ = *_NSGetEnviron(); environ = *_NSGetEnviron();
@@ -1124,6 +1145,8 @@ int main(int argc, const char **argv)
evil_C= C; evil_C= C;
#endif #endif
#ifdef WITH_BINRELOC #ifdef WITH_BINRELOC
br_init( NULL ); br_init( NULL );
#endif #endif
@@ -1245,6 +1268,15 @@ int main(int argc, const char **argv)
BLI_argsFree(ba); BLI_argsFree(ba);
#ifdef WIN32
while(argci)
{
free(argv[--argci]);
}
MEM_freeN(argv);
argv = NULL;
#endif
#ifdef WITH_PYTHON_MODULE #ifdef WITH_PYTHON_MODULE
return 0; /* keep blender in background mode running */ return 0; /* keep blender in background mode running */
#endif #endif