简体   繁体   中英

P4.Net and P4CHARSET

I'm using P4.Net to connect to my non-unicode server however some commands i run fail with:

              "Unicode clients require a unicode enabled server."

how do i change the P4CHARSET to none in P4.Net? I've tried

              P4Connection p4 = new P4Connection();
              p4.Charset = "none"
              p4.Connect()

i've also tried changing the Charset just before the p4.Run command:

              p4.Charset = "none"
              p4.Run("where", "c:\\some\\random\\dir");

i've tried setting the Charset to "none", null and "".

if i try passing global options to the p4.Run command it doesn't work either. ie.

              p4.Run("-C none where", "c:\\some\\random\\dir");

fails with "Unknown Command"

has anyone had any success with changing the P4CHARSET within a P4.Net script? how do you do it?

Have you tried nuking P4CHARSET and P4COMMANDCHARSET from your registry settings? They should be at HKEY_CURRENT_USER.Software.Perforce.Environment. I've been in a situation similar to yours before and that's how I ended up fixing it.

Also, are you using P4Win or P4V? I'm not entirely sure about P4V, but I know P4Win seemed to store charset information per connection. Maybe that could be interfering with P4.NET somehow?

UPDATE

The C++ API was detecting a Unicode charset because the P4CHARSET was set to none. Running p4 set P4CHARSET= from the command line fixed the issue for the poster.

I think the problem is the following code in ClientApi_m.cpp:


 void p4dn::ClientApi::Init( p4dn::Error* e ) 
 { 
    if(getClientApi()->GetCharset().Length() > 0)
    {
        // unicode server use UTF-8
        _encoding = new System::Text::UTF8Encoding();

        // set the translations (use UTF-8 for everything but content).
        CharSetApi::CharSet content = CharSetApi::Lookup(getClientApi()->GetCharset().Text());
        getClientApi()->SetTrans(CharSetApi::CharSet::UTF_8, content, 
            CharSetApi::CharSet::UTF_8, CharSetApi::CharSet::UTF_8);
    }
    else
    {
        // non-unicode server use ANSI encoding
        _encoding = System::Text::Encoding::GetEncoding(1252);
    }
    getClientApi()->Init( e->get_InternalError() );
 }

because getClientApi()->GetCharset().Length() is non-zero for non-unicode servers also, ie. P4CHARSET is "none" .

if I set the translation using getClientApi()->SetTrans(0, 0, 0, 0); where 0 is CharSetApi::CharSet::NOCONV it works.

i guess i'll have to use modified source. that sucks.

does anyone have a better way to do this?

p4.Charset设置为"iso8859-1"或其他一些字符集。

If you're connecting to a non-unicode server, you shouldn't set p4.Charset at all. If you're making a client that needs to connect to both unicode, and non-unicode enabled servers, then I think you can set Charset to an empty-string for non-unicode, and one of the valid charsets otherwise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM