Exemplo n.º 1
0
size_t LongestCommonSubstringLength(const wstring& str1, const wstring& str2) {
  if (str1.empty() || str2.empty())
    return 0;

  const size_t len1 = str1.length();
  const size_t len2 = str2.length();

  vector<vector<size_t>> table(len1);
  for (auto it = table.begin(); it != table.end(); ++it)
    it->resize(len2);

  size_t longest_length = 0;

  for (size_t i = 0; i < len1; i++) {
    for (size_t j = 0; j < len2; j++) {
      if (str1[i] == str2[j]) {
        if (i == 0 || j == 0) {
          table[i][j] = 1;
        } else {
          table[i][j] = table[i - 1][j - 1] + 1;
        }
        if (table[i][j] > longest_length) {
          longest_length = table[i][j];
        }
      } else {
        table[i][j] = 0;
      }
    }
  }

  return longest_length;
}
Exemplo n.º 2
0
BOOL CWaveSession::Login(wstring szUsername, wstring szPassword)
{
	ASSERT(!szUsername.empty() && !szPassword.empty());

	if (m_nState != WSS_OFFLINE)
	{
		LOG("Not offline");
		return FALSE;
	}

	if (m_lpRequest != NULL)
	{
		LOG("Requesting login while a request is running");
		return FALSE;
	}

	m_nState = WSS_CONNECTING;

	SignalProgress(WCS_BEGIN_LOGON);

	m_szUsername = szUsername;
	m_szPassword = szPassword;

	return Reconnect();
}
Exemplo n.º 3
0
connection_spec::connection_spec(
    const wstring& host, const wstring& user, const int port)
: m_host(host), m_user(user), m_port(port)
{
    if (host.empty())
        BOOST_THROW_EXCEPTION(invalid_argument("Host name required"));
    if (user.empty())
        BOOST_THROW_EXCEPTION(invalid_argument("User name required"));
}
Exemplo n.º 4
0
void AppendString(wstring& str0, const wstring& str1, const wstring& str2) {
  if (str1.empty())
    return;

  if (!str0.empty())
    str0.append(str2);

  str0.append(str1);
}
Exemplo n.º 5
0
void Localization::set(wstring &key, wstring &val)
{
    if (!key.empty() && !val.empty()) {
        STR::unescape_simple(key);
        STR::unescape_simple(val);
        // dwprintf(L">> %s\n", key.c_str());

        mMenu[key] = val;
    }
}
Exemplo n.º 6
0
HTTPParameters BuildSignedOAuthParameters( const HTTPParameters& requestParameters, 
								   const wstring& url, 
								   const wstring& httpMethod, 
								   const HTTPParameters* postParameters, 
								   const wstring& consumerKey, 
								   const wstring& consumerSecret,
								   const wstring& requestToken = L"", 
								   const wstring& requestTokenSecret = L"", 
								   const wstring& pin = L"" )
{
	wstring timestamp = OAuthCreateTimestamp();
	wstring nonce = OAuthCreateNonce();

	// create oauth requestParameters
	HTTPParameters oauthParameters;

	oauthParameters[L"oauth_timestamp"] = timestamp;
	oauthParameters[L"oauth_nonce"] = nonce;
	oauthParameters[L"oauth_version"] = L"1.0";
	oauthParameters[L"oauth_signature_method"] = L"HMAC-SHA1";
	oauthParameters[L"oauth_consumer_key"] = consumerKey;

	// add the request token if found
	if (!requestToken.empty())
	{
		oauthParameters[L"oauth_token"] = requestToken;
	}

	// add the authorization pin if found
	if (!pin.empty())
	{
		oauthParameters[L"oauth_verifier"] = pin;
	}

	// create a parameter list containing both oauth and original parameters
	// this will be used to create the parameter signature
	HTTPParameters allParameters = requestParameters;
	if(Compare(httpMethod, L"POST", false) && postParameters)
	{
		allParameters.insert(postParameters->begin(), postParameters->end());
	}
	allParameters.insert(oauthParameters.begin(), oauthParameters.end());

	// prepare a signature base, a carefully formatted string containing 
	// all of the necessary information needed to generate a valid signature
	wstring normalUrl = OAuthNormalizeUrl(url);
	wstring normalizedParameters = OAuthNormalizeRequestParameters(allParameters);
	wstring signatureBase = OAuthConcatenateRequestElements(httpMethod, normalUrl, normalizedParameters);

	// obtain a signature and add it to header requestParameters
	wstring signature = OAuthCreateSignature(signatureBase, consumerSecret, requestTokenSecret);
	oauthParameters[L"oauth_signature"] = signature;

	return oauthParameters;
}
Exemplo n.º 7
0
void ConsoleHandler::RunAsAdministrator
(
	const wstring& strSyncName,
	const wstring& strTitle,
	const wstring& strInitialDir,
	const wstring& strInitialCmd,
	PROCESS_INFORMATION& pi
)
{
	std::wstring strFile = Helpers::GetModuleFileName(nullptr);

	std::wstring strParams;
	// admin sync name
	strParams += L"-a ";
	strParams += Helpers::EscapeCommandLineArg(strSyncName);
	// config file
	strParams += L" -c ";
	strParams += Helpers::EscapeCommandLineArg(g_settingsHandler->GetSettingsFileName());
	// tab name
	strParams += L" -t ";
	strParams += Helpers::EscapeCommandLineArg(strTitle);
	// directory
	if (!strInitialDir.empty())
	{
		strParams += L" -d ";
		strParams += Helpers::EscapeCommandLineArg(strInitialDir);
	}
	// startup shell command
	if (!strInitialCmd.empty())
	{
		strParams += L" -r ";
		strParams += Helpers::EscapeCommandLineArg(strInitialCmd);
	}

	SHELLEXECUTEINFO sei = {sizeof(sei)};

	sei.hwnd = nullptr;
	sei.fMask = /*SEE_MASK_NOCLOSEPROCESS|*/SEE_MASK_NOASYNC;
	sei.lpVerb = L"runas";
	sei.lpFile = strFile.c_str();
	sei.lpParameters = strParams.length() > 0 ? strParams.c_str() : nullptr;
	sei.lpDirectory = nullptr,
	sei.nShow = SW_SHOWMINIMIZED;

	if(!::ShellExecuteEx(&sei))
	{
		Win32Exception err(::GetLastError());
		throw ConsoleException(boost::str(boost::wformat(Helpers::LoadString(IDS_ERR_CANT_START_SHELL_AS_ADMIN)) % strFile % strParams % err.what()));
	}

	pi.hProcess = sei.hProcess;
	pi.dwProcessId = ::GetProcessId(sei.hProcess);
	pi.hThread = NULL;
	pi.dwThreadId = 0;
}
Exemplo n.º 8
0
extern "C" const wchar_t *
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
{
    switch (pathType) {
        case SDL_WINRT_PATH_INSTALLED_LOCATION:
        {
            static wstring path;
            if (path.empty()) {
                path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
            }
            return path.c_str();
        }

        case SDL_WINRT_PATH_LOCAL_FOLDER:
        {
            static wstring path;
            if (path.empty()) {
                path = ApplicationData::Current->LocalFolder->Path->Data();
            }
            return path.c_str();
        }

#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
        case SDL_WINRT_PATH_ROAMING_FOLDER:
        {
            static wstring path;
            if (path.empty()) {
                path = ApplicationData::Current->RoamingFolder->Path->Data();
            }
            return path.c_str();
        }

        case SDL_WINRT_PATH_TEMP_FOLDER:
        {
            static wstring path;
            if (path.empty()) {
                path = ApplicationData::Current->TemporaryFolder->Path->Data();
            }
            return path.c_str();
        }
#endif

        default:
            break;
    }

    SDL_Unsupported();
    return NULL;
}
void IEAcceptLanguagesAction::_createRegistryString(wstring &regvalue)
{
	wchar_t szFormat[128];
	int languages = m_languages.size();	
	float average, value, cal;

	if (languages == 1)
	{
		regvalue = m_languages.at(0);
		return;
	}

	average = 100 / (float) languages;
	regvalue.empty();
	_createRegistryStringTwoLangs(regvalue, average);
	
	// More than 2 languages	
	for (int i = 2; i < languages; i++)
	{
		cal = 100 - (average * i);
		value = floor(cal) / 100;
		swprintf_s(szFormat, L",%s;q=%1.1f",  m_languages.at(i).c_str(), value);
		regvalue += szFormat;		
	}
}
Exemplo n.º 10
0
ns1__user* Server::Connector::AuthenticateByKerberos() {
	LOG_DEBUG("call AuthenticateByKerberos ...");
	const wstring kerberosServerName = RtnResources::GetOption(L"kerberos.spn", L"");
	if (kerberosServerName.empty()) {
		throw "Required property 'kerberos.spn' is not set";
	}
	const string ticket = Auth::GetKerberosTicket(kerberosServerName);
	if(ticket.empty()) {
		LOG_ERROR("GetKerberosTicket failed");
		return false;
	}
	ns1__authenticateByKerberos request;
	const unsigned char* tokenPointer = reinterpret_cast<const unsigned char*>(ticket.c_str());
	request.token = new xsd__base64Binary();
	request.token->__ptr = const_cast<unsigned char*>(tokenPointer);
	request.token->__size = ticket.length();
	ns1__authenticateByKerberosResponse response;
	string authenticationUrl = IO::ToString(RtnResources::GetWebServiceURL(serverType, serverVersion, L"Authentication"));
	ServerAPIBindingProxy authProxy(authenticationUrl.c_str());
	int result = authProxy.authenticateByKerberos(&request, &response);
    if (result == SOAP_OK) {
        LOG_DEBUG("call AuthenticateByKerberos completed");
		return response.result;
    } else {
		LOG_ERROR("call AuthenticateByKerberos failed by '%s'", authenticationUrl.c_str());
		Logger::LogWebServiceError(&authProxy);
		return NULL;
	}
	// TODO authProxy.destroy(); if copy constructor for class ns1__user will be available
}
Exemplo n.º 11
0
/*!
	sakura.iniの1行を処理する.

	1行の読み込みが完了するごとに呼ばれる.
	
	@param line [in] 読み込んだ行
*/
void CProfile::ReadOneline(
	const wstring& line
)
{
	//	空行を読み飛ばす
	if( line.empty() )
		return;

	//コメント行を読みとばす
	if( 0 == line.compare( 0, 2, LTEXT("//") ))
		return;

	// セクション取得
	//	Jan. 29, 2004 genta compare使用
	if( line.compare( 0, 1, LTEXT("[") ) == 0 
			&& line.find( LTEXT("=") ) == line.npos
			&& line.find( LTEXT("]") ) == ( line.size() - 1 ) ) {
		Section Buffer;
		Buffer.strSectionName = line.substr( 1, line.size() - 1 - 1 );
		m_ProfileData.push_back( Buffer );
	}
	// エントリ取得
	else if( !m_ProfileData.empty() ) {	//最初のセクション以前の行のエントリは無視
		wstring::size_type idx = line.find( LTEXT("=") );
		if( line.npos != idx ) {
			m_ProfileData.back().mapEntries.insert( PAIR_STR_STR( line.substr(0,idx), line.substr(idx+1) ) );
		}
	}
}
Exemplo n.º 12
0
BOOL CADOParameter::SetValue(wstring strValue)
{
	_variant_t vtVal;

	ASSERT(m_pParameter != NULL);
	
    if(!strValue.empty())
		vtVal.vt = VT_BSTR;
	else
		vtVal.vt = VT_NULL;

    vtVal.bstrVal = _bstr_t(strValue.c_str());

	try
	{
		if(m_pParameter->Size == 0)
            m_pParameter->Size = sizeof(char) * strValue.length();

		m_pParameter->Value = vtVal;
		::SysFreeString(vtVal.bstrVal);
		return TRUE;
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
		::SysFreeString(vtVal.bstrVal);
		return FALSE;
	}
}
Exemplo n.º 13
0
//选择一个新的采集器 directsound or wasapi
AudioInputPtr AudioInputRegistrar::newFromChoice(wstring choice) {
	if (! qmNew)
		return AudioInputPtr();

	if (!choice.empty() && qmNew->find(choice) != qmNew->end()) {
		g_struct.s.qsAudioInput = choice;
		current = choice;
		AudioInputRegistrar * air = qmNew->find(current)->second;
		
		return AudioInputPtr(air->create());
	}
	choice = g_struct.s.qsAudioInput;
	if (qmNew->find(choice) != qmNew->end()) {
		current = choice;
		return AudioInputPtr(qmNew->find(choice)->second->create());
	}

	AudioInputRegistrar *r = NULL;
	std::map<wstring, AudioInputRegistrar *>::iterator mit;
	for (mit = qmNew->begin(); mit != qmNew->end(); mit++)
	{
		if (!r || (mit->second->priority > r->priority))
			r = mit->second;
	}
	if (r) {
		current = r->name;
		g_struct.s.qsAudioInput = current;
		return AudioInputPtr(r->create());
	}
	return AudioInputPtr();
}
Exemplo n.º 14
0
    void split(const wstring & ws, const wstring & delim, WStringList & out)
    {
      out.clear();

      if(ws.empty())
      {
        return;
      }

      // Find first a delimiter
      wstring   wscopy(ws);
      size_t    pos = wscopy.find_first_of(delim);

      // Loop until no delimiters left
      while(pos != wscopy.npos)
      {
        out.push_back(wscopy.substr(0, pos + 1));
        wscopy.erase(0, pos + 1);
        pos = wscopy.find_first_of(delim);
      }

      // Push remainder of wstring onto list
      if(!wscopy.empty())
      {
        out.push_back(wscopy);
      }
    }
Exemplo n.º 15
0
void PerfTest::StartClient()
{
#ifdef PLATFORM_UNIX
    console.WriteLine("client process needs to be started manually on Linux");
#else

    if (!computer.empty())
    {
        StartClientOnRemoteComputer();
        return;
    }

    auto cmdline = wformatString(
        "{0} {1} {2}",
        Path::Combine(Environment::GetExecutablePath(), clientExeName),
        listener_->ListenAddress(),
        securityProvider_);

    console.WriteLine("{0}", cmdline);

    HandleUPtr processHandle, threadHandle;
    vector<wchar_t> envBlock = vector<wchar_t>();

    auto error = ProcessUtility::CreateProcess(
        cmdline,
        wstring(),
        envBlock,
        0,
        processHandle,
        threadHandle);

    Invariant(error.IsSuccess());
#endif
}
Exemplo n.º 16
0
bool mod_patch::patchModuleOfPID(DWORD pid, wstring moduleName, BYTE * patternToSearch, SIZE_T szPatternToSearch, BYTE * patternToPlace, SIZE_T szPatternToPlace, long offsetForPlace)
{
	bool reussite = false;

	mod_process::KIWI_MODULEENTRY32 monModule;
	if(mod_process::getUniqueModuleForName(&monModule, (moduleName.empty() ? NULL : &moduleName), &pid))
	{
		BYTE * baseAddr = monModule.modBaseAddr;
		DWORD taille = monModule.modBaseSize;

		if(HANDLE processHandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, pid))
		{
			(*outputStream) << L"Recherche des patterns dans : " << moduleName << L"@pid(" << pid << L")" << endl;

			BYTE * addrPattern = NULL;
			if(mod_memory::searchMemory(baseAddr, baseAddr + taille, patternToSearch, &addrPattern, szPatternToSearch, true, processHandle))
			{
				reussite = mod_memory::writeMemory(addrPattern + offsetForPlace, patternToPlace, szPatternToPlace, processHandle);
				(*outputStream) << L"Patch " << moduleName << L"@pid(" << pid << L") : " << (reussite ? L"OK" : L"KO") << endl;
			}
			else (*outputStream) << L"mod_memory::searchMemory " << mod_system::getWinError() << endl;

			CloseHandle(processHandle);
		}
		else (*outputStream) << L"OpenProcess : " << mod_system::getWinError() << endl;
	}
	else (*outputStream) << L"mod_process::getUniqueModuleForName : " << mod_system::getWinError() << endl;
	return reussite;
}
Exemplo n.º 17
0
Process Process::findByWindow(wstring className, wstring windowName)
{
	HWND hwnd = FindWindowW(className.empty() ? nullptr : className.c_str(), windowName.empty() ? nullptr : windowName.c_str());
	if (!hwnd)
	{
		DWORD errcode = GetLastError();
		BOOST_THROW_EXCEPTION(ex_injection() << e_api_function("FindWindow") << e_text("could not find window class:'" + to_string(className) + "' title:'" + to_string(windowName) + "'") << e_last_error(errcode));
	}

	pid_t pid = 0;
	GetWindowThreadProcessId(hwnd, &pid);
	if (pid == 0)
		BOOST_THROW_EXCEPTION(ex_injection() << e_api_function("GetWindowThreadProcessId") << e_text("could not get process id for window class:'" + to_string(className) + "' title:'" + to_string(windowName) + "'"));

	return Process::open(pid);
}
Exemplo n.º 18
0
void ExTextBox::SetText(wstring sLabel)
{
	bool erased = false;
	wstring szLabel = sLabel;
	if (sLabel.empty())
		return;
	for (wstring::iterator temp = szLabel.end(); temp != szLabel.begin(); --temp)
	{
		cWidth = ExScreen::GetTextWidthEx(szLabel.c_str(), aFont);
		int viewEnd = *D2Vars.D2CLIENT_ScreenWidth;
		if (pParent) {
			viewEnd = pParent->GetWidth();
			if (viewEnd == -1)
				viewEnd = *D2Vars.D2CLIENT_ScreenWidth;
		}
		if (cWidth <= viewEnd) break;
		szLabel.erase(temp);
		erased = true;
	}
	if (erased) { szLabel.erase(szLabel.length() - 3); szLabel += L"..."; cWidth = ExScreen::GetTextWidthEx(szLabel.c_str(), aFont); }
	cHeight = ExScreen::GetTextHeight(aFont);
	Relocate();

	Label = szLabel;

}
Exemplo n.º 19
0
void NormalizeDirPathPrefix(wstring & dirPath)
{
	if (dirPath.empty())
		return;
	if (dirPath.rfind(wchar_t(kDirDelimiter)) != dirPath.length() - 1)
		dirPath += wchar_t(kDirDelimiter);
}
Exemplo n.º 20
0
    bool WstringToString(UINT nCodePage, const wstring& wstr, string& str)
    {
        bool fRet = false;
        char* pBuffer = NULL;
        size_t nSize = 0;

        if (wstr.empty())
            goto END;

        nSize = wstr.size();
        pBuffer = new char[nSize + 1];
        if (!pBuffer)
            goto END;

        memset(pBuffer, 0, sizeof(char) * (nSize + 1));

        if (!WideCharToMultiByte(nCodePage, 0, wstr.c_str(), nSize, pBuffer, nSize + 1, NULL, NULL))
            goto END;

        str = pBuffer;

        // Done
        fRet = true;      

    END:
        if (pBuffer)
            delete[] pBuffer;

        return fRet;
    }    
Exemplo n.º 21
0
string
IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter)
{
    string target;
    if(!v.empty())
    {
        const WstringConverterPtr& wConverterWithDefault = wConverter ? wConverter : getUnicodeWstringConverter();

        //
        // First convert to UTF-8 narrow string.
        //
        UTF8BufferI buffer;
        Byte* last = wConverterWithDefault->toUTF8(v.data(), v.data() + v.size(), buffer);
        buffer.swap(target, last);

        //
        // If narrow string converter is present convert to the native narrow string encoding, otherwise
        // native narrow string encoding is UTF8 and we are done.
        //
        if(converter)
        {
            string tmp;
            converter->fromUTF8(reinterpret_cast<const Byte*>(target.data()),
                                reinterpret_cast<const Byte*>(target.data() + target.size()), tmp);
            tmp.swap(target);
        }
    }
    return target;
}
Exemplo n.º 22
0
void CRenderFont::UpdateCharInfo( const wstring& text )
{
	if ( text.empty() || text.length() == 0 )
		return;

	realFont->UpdateCharInfo(text);
}
void vmsHttpFlvTrafficAnalyzer::DecodeWebPageString(const vmsHttpTrafficCollector::HttpDialog* pHtmlDlg, LPCSTR pszString, wstring &wstrResult)
{
	const vmsHttpParser::HdrField *pFld = pHtmlDlg->pHttpResponse->FieldByName ("Content-Type");
	LPCSTR pszCharset = pFld ? strstr (pFld->strValue.c_str (), "charset") : NULL;
	if (pszCharset)
	{
		pszCharset += 7;
		while (*pszCharset == ' ')
			pszCharset++;
		if (*pszCharset == '=')
		{
			pszCharset++;
			while (*pszCharset == ' ')
				pszCharset++;
			string strCharset;
			while (*pszCharset != ' ' && *pszCharset != 0)
				strCharset += *pszCharset++;
			UINT nCP = vmsCharsets::GetCpIdFromName (strCharset.c_str ());
			if (nCP)
				vmsCharsets::DecodeString (pszString, nCP, wstrResult);
		}
	}
	if (wstrResult.empty ())
		vmsCharsets::DecodeString (pszString, CP_UTF8, wstrResult);
}
Exemplo n.º 24
0
    /**
        Extract a vector of the substrings that are separated by the delimter string

        \param    str          String to tokenize
        \param    tokens       Return a vector of tokens
        \param    delimiter    Delimeter string
        \param    trim         true if all tokens should be trimmed (default), otherwise false
        \param    emptyTokens  false if empty tokens should be removed from the result (default), otherwise true.

    */
    void StrTokenizeStr(const wstring& str, vector<std::wstring>& tokens, const wstring& delimiter, bool trim/*=true*/, bool emptyTokens/*=false*/)
    {
        tokens.clear();

        wstring::size_type lastPos = 0;
        wstring::size_type pos = delimiter.empty()?wstring::npos:str.find(delimiter, lastPos);

        while (wstring::npos != pos)
        {
            wstring tmp = str.substr(lastPos, pos - lastPos);
            if ( ! tmp.empty() && trim)
            {
                tmp = StrTrim(tmp);
            }
            if ( ! tmp.empty() || emptyTokens)
            {
                tokens.push_back(tmp);
            }
            lastPos = pos + delimiter.length();
            //if (pos != wstring::npos)
            {
                pos = str.find(delimiter, lastPos);
            }
        }
        wstring tmp = str.substr(lastPos, wstring::npos);
        if ( ! tmp.empty() && trim)
        {
            tmp = StrTrim(tmp);
        }
        if ( ! tmp.empty() || emptyTokens)
        {
            tokens.push_back(tmp);
        }
    }
Exemplo n.º 25
0
void Utils::rtrim(wstring& s, const wchar_t c)
{
    while (!s.empty() && s.back() == c)
    {
        s.pop_back();
    }
}
Exemplo n.º 26
0
Arquivo: Err.cpp Projeto: 3dik/MPong
//Set
bool Err::Set (wstring sErr)
{
    if (sErr.empty ())
    {
        sErr = L"Error text not specified";
    }

    if (m_pMainErr == NULL) //This object is the main error object
    {
        OPut (L"Error: " + sErr);
        m_bError = true;
        return false;
    }
    if (!IsClass ())
    {
        m_pMainErr->Set (sErr); //The class error object process further
        return false;
    }

    m_pMainErr->GetMain ()->Set (m_sClassName +
                                 L"->" +
                                 m_lsFunctions.back () +
                                 L" : " +
                                 sErr);
    return false;
}//Set
Exemplo n.º 27
0
void Replace(wstring& input, wstring find, wstring replace_with,
             bool replace_all, bool case_insensitive) {
  if (find.empty() || find == replace_with || input.length() < find.length())
    return;

  if (!case_insensitive) {
    for (size_t pos = input.find(find); pos != wstring::npos;
         pos = input.find(find, pos)) {
      input.replace(pos, find.length(), replace_with);
      if (!replace_all)
        pos += replace_with.length();
    }
  } else {
    for (size_t i = 0; i < input.length() - find.length() + 1; i++) {
      for (size_t j = 0; j < find.length(); j++) {
        if (input.length() < find.length())
          return;
        if (tolower(input[i + j]) == tolower(find[j])) {
          if (j == find.length() - 1) {
            input.replace(i--, find.length(), replace_with);
            if (!replace_all)
              i += replace_with.length();
            break;
          }
        } else {
          i += j;
          break;
        }
      }
    }
  }
}
Exemplo n.º 28
0
bool Twitter::SetStatusText(const wstring& status_text) {
  if (Settings.Announce.Twitter.oauth_key.empty() || Settings.Announce.Twitter.oauth_secret.empty()) {
    return false;
  }
  if (status_text.empty() || status_text == status_text_) {
    return false;
  }
  status_text_ = status_text;

  OAuthParameters post_parameters;
  post_parameters[L"status"] = EncodeUrl(status_text_);

  wstring header = 
    Clients.sharing.twitter.GetDefaultHeader() + 
    oauth.BuildHeader(
      L"https://api.twitter.com/1.1/statuses/update.json", 
      L"POST", &post_parameters, 
      Settings.Announce.Twitter.oauth_key, 
      Settings.Announce.Twitter.oauth_secret);

  Clients.sharing.twitter.SetHttpsEnabled(TRUE);

  return Clients.sharing.twitter.Connect(
    L"api.twitter.com", L"1.1/statuses/update.json", 
    L"status=" + post_parameters[L"status"],
    L"POST", header, L"myanimelist.net", L"", 
    HTTP_Twitter_Post);
}
Exemplo n.º 29
0
wstring PushString(const wstring& str1, const wstring& str2) {
  if (str2.empty()) {
    return L"";
  } else {
    return str1 + str2;
  }
}
Exemplo n.º 30
0
/* -----------------------------------------------------------------------
 *  関数名  :  ws_fgets
 *  機能概要:  wstringに取り出せる簡易版fgets、暗号復号とUCS-2 BOM削除も行なう
 * -----------------------------------------------------------------------
 */
int ws_fgets(wstring &str, FILE *stream, int charset, int ayc/*1でAYC復号する*/, int lc/*1でBOMチェックON*/) {
    string buf;
    int c;
    while (true) {
	c = fgetc(stream);
	if (c == EOF) {
	    break;
	}
	if (ayc) {
	    decodecipher(c);
	}
	buf += static_cast<char>(c);
	if (c == '\x0a') {
	    // 行の終わり
	    break;
	}
    }

    wchar_t *wstr = Ccct::MbcsToUcs2(buf, charset);
    str = wstr;
    free(wstr);

    if (charset == CHARSET_UTF8 && lc == 1) {
	cutbom(str);
    }

    if (c == EOF && str.empty()) {
	return WS_EOF;
    }
    else {
	return str.size();
    }
}