Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Path including non-English character, buglog and usrlog file cannot be deleted
Path including non-English character, buglog and usrlog file cannot be deleted [message #17572] Thu, 21 August 2008 09:16 Go to next message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
In the debug mode, when the path of execute file including non-English character, like Chinese, buglog and usrlog cannot be deleted after the execute file terminated.

the content of buglog and usrlog file is as the following:

36.MainMenu with layout.2008-08-21-14-21-45.buglog:

* c:\Program Files\OpenCV\MyCode\build\win32\debug\´ú¸ÕÀÉ\36.MainMenu with layout.exe 21.08.2008 14:21:45, user: kasome


36.MainMenu with layout.2008-08-21-14-21-45.usrlog:

* c:\Program Files\OpenCV\MyCode\build\win32\debug\´ú¸ÕÀÉ\36.MainMenu with layout.exe 21.08.2008 14:21:45, user: kasome


and i find out the reason may be the file

uppsrc\Core\Path.cpp

in the following function:

bool FileDelete(const char *filename)
{
#if defined(PLATFORM_WIN32)
	if( IsWinNT() ){
		return !!UnicodeWin32().DeleteFileW( ToSystemCharsetW(filename) );
	}
	else
		return !!DeleteFile(ToSystemCharset(filename));
#elif defined(PLATFORM_POSIX)
	return !unlink(ToSystemCharset(filename));
#else
	#error
#endif//PLATFORM
}



i keep trying and finally fix the function as the following, this function WideString can be found in the attachment file got from the internet.

bool FileDelete(const char *filename)
{
#if defined(PLATFORM_WIN32)
	if( IsWinNT() ){
		return !!UnicodeWin32().DeleteFileW( ToSystemCharsetW( ToUtf8( WideString( filename ) ) ) );
	}
	else
		return !!DeleteFile(ToSystemCharset(filename));
#elif defined(PLATFORM_POSIX)
	return !unlink(ToSystemCharset(filename));
#else
	#error
#endif//PLATFORM
}


WideString.h
#include <windows.h>
#include <CtrlLib/CtrlLib.h>
#include <iostream>

using namespace std;
using namespace Upp;

WString WideString( const String s );


WideString.cpp
#include "WideString.h"

WString WideString( const String s ){

	int nIndex = MultiByteToWideChar( CP_ACP, 0, s, -1, NULL, 0 );
	wchar_t *w = new wchar_t[ nIndex + 1 ];
	MultiByteToWideChar( CP_ACP, 0, s, -1, w, nIndex );
	WString wstr = w;
	delete[] w; w = 0;

	return wstr;
}


now everthing is work fine, but i can not explain why, may be there is a more better way to solve this.

OS: Microsoft Windows XP Professional SP2
Language: Taiwan (codepage 950 )

[Updated on: Thu, 21 August 2008 09:31]

Report message to a moderator

Re: Path including non-English character, buglog and usrlog file cannot be deleted [message #17582 is a reply to message #17572] Thu, 21 August 2008 16:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kasome wrote on Thu, 21 August 2008 03:16

In the debug mode, when the path of execute file including non-English character, like Chinese, buglog and usrlog cannot be deleted after the execute file terminated.

the content of buglog and usrlog file is as the following:

36.MainMenu with layout.2008-08-21-14-21-45.buglog:

* c:\Program Files\OpenCV\MyCode\build\win32\debug\´ú¸ÕÀÉ\36.MainMenu with layout.exe 21.08.2008 14:21:45, user: kasome


36.MainMenu with layout.2008-08-21-14-21-45.usrlog:

* c:\Program Files\OpenCV\MyCode\build\win32\debug\´ú¸ÕÀÉ\36.MainMenu with layout.exe 21.08.2008 14:21:45, user: kasome


and i find out the reason may be the file

uppsrc\Core\Path.cpp

in the following function:

bool FileDelete(const char *filename)
{
#if defined(PLATFORM_WIN32)
	if( IsWinNT() ){
		return !!UnicodeWin32().DeleteFileW( ToSystemCharsetW(filename) );
	}
	else
		return !!DeleteFile(ToSystemCharset(filename));
#elif defined(PLATFORM_POSIX)
	return !unlink(ToSystemCharset(filename));
#else
	#error
#endif//PLATFORM
}



i keep trying and finally fix the function as the following, this function WideString can be found in the attachment file got from the internet.

bool FileDelete(const char *filename)
{
#if defined(PLATFORM_WIN32)
	if( IsWinNT() ){
		return !!UnicodeWin32().DeleteFileW( ToSystemCharsetW( ToUtf8( WideString( filename ) ) ) );
	}
	else
		return !!DeleteFile(ToSystemCharset(filename));
#elif defined(PLATFORM_POSIX)
	return !unlink(ToSystemCharset(filename));
#else
	#error
#endif//PLATFORM
}


WideString.h
#include <windows.h>
#include <CtrlLib/CtrlLib.h>
#include <iostream>

using namespace std;
using namespace Upp;

WString WideString( const String s );


WideString.cpp
#include "WideString.h"

WString WideString( const String s ){

	int nIndex = MultiByteToWideChar( CP_ACP, 0, s, -1, NULL, 0 );
	wchar_t *w = new wchar_t[ nIndex + 1 ];
	MultiByteToWideChar( CP_ACP, 0, s, -1, w, nIndex );
	WString wstr = w;
	delete[] w; w = 0;

	return wstr;
}


now everthing is work fine, but i can not explain why, may be there is a more better way to solve this.

OS: Microsoft Windows XP Professional SP2
Language: Taiwan (codepage 950 )



Thanks. Handling CJK is always full of surprises Smile

Hm, if this works well, I believe that the construct should be embedded into ToSystemCharsetW, correct?

Can you try to put it there and create / delete a couple of files with CJK filenames?

Mirek
Re: Path including non-English character, buglog and usrlog file cannot be deleted [message #17773 is a reply to message #17582] Thu, 28 August 2008 14:50 Go to previous messageGo to next message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
I am so sorry replying late. Here is my some result.

When i put "ToUtf8( WideString( filename )" to the function "ToSystemCharsetW". i found something wrong when i try to delete and create file with Chinese filenames, so i try to trace the code. Finally, i find out the better solution.


just find the code in

c:\upp\uppsrc\Core\Log.cpp
bool LogStream::Delete()
{
	Close();
	if(*filename) {
		if( !FileDelete( filename ) ) {
			BugLog() << "Error deleting " << filename << ": " << GetLastErrorMessage();
			return false;
		}
		*filename = 0;
	}
	return true;
}



and fix as the following
bool LogStream::Delete()
{
	Close();
	if(*filename) {
		if( !FileDelete( FromSystemCharset(filename) ) ) {
			BugLog() << "Error deleting " << filename << ": " << GetLastErrorMessage();
			return false;
		}
		*filename = 0;
	}
	return true;
}


The function "FromSystemCharset" embbed in U++ and the function "WideString" is equivilent.

Because "FileDelete" should take UTF8 string as argument, and filename seem to just the ansi string, covert ansi string to utf8 by the function "FromSystemCharset" should solve the problem (e.g. the problem when path including non-English character, buglog and usrlog file cannot be deleted).

Now everything is work fine. ( i hope so Very Happy )


BTW, here is some test code i wrote to test the two function (in c:\upp\uppsrc\Core\Path.cpp ) "FileDelete" and "DirectoryDelete" in processing file with the path including chinese characters, and it works very well in my OS.These two function has no problem when i test.

index.php?t=getfile&id=1343&private=0

U++ is an amazing Tool. Thank you. Very Happy

[Updated on: Thu, 28 August 2008 15:03]

Report message to a moderator

Re: Path including non-English character, buglog and usrlog file cannot be deleted [message #17776 is a reply to message #17773] Thu, 28 August 2008 15:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I do not know, I still do not like it Smile

The file is created using:

	hfile = CreateFile(ToSysChrSet(filename),


therefore I would expect the correct solution to be

		if(!FileDelete(ToSysChrSet(filename))) {


Would that work for you?

Mirek
Re: Path including non-English character, buglog and usrlog file cannot be deleted [message #17777 is a reply to message #17776] Thu, 28 August 2008 15:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Note: ToSysChrSet is used instead of ToSystemCharset because LogStream is carefully designed to work even if everything else is corrupted, e.g. without the heap (which is needed for String).

Mirek
Re: Path including non-English character, buglog and usrlog file cannot be deleted [message #17782 is a reply to message #17777] Thu, 28 August 2008 16:33 Go to previous message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
if(!FileDelete(ToSysChrSet(filename))) {


//I see. I have try it, and yes, it can work totally. Thanks you very much. Very Happy

Sorry. I think i make some mistake by building with release mode, so i say it works totally, but it not true.

In fact, when i using
if(!FileDelete(ToSysChrSet(filename))) {


the log file( *.usrlog, *.buglog ) still can't deleted.

i am sorry for this mistake.

[Updated on: Thu, 28 August 2008 17:59]

Report message to a moderator

Previous Topic: Some 'missing' string functions
Next Topic: String filter whitespace
Goto Forum:
  


Current Time: Sat Apr 20 03:51:42 CEST 2024

Total time taken to generate the page: 0.07420 seconds