P4.Net and P4CHARSET

﹥>﹥吖頭↗ 提交于 2019-12-20 02:29:35

问题


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?


回答1:


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.




回答2:


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?




回答3:


Set p4.Charset to "iso8859-1" or some other charset.




回答4:


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.



来源:https://stackoverflow.com/questions/5240500/p4-net-and-p4charset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!