void C4StartupMainDlg::OnPlayerSelContextAddPlr(C4GUI::Element *pTarget, const StdCopyStrBuf &rsFilename) { // De-select all other players for now (see #1529) SCopy(rsFilename.getData(), Config.General.Participants); //SAddModule(Config.General.Participants, rsFilename.getData()); UpdateParticipants(); }
void CPNGSaveThread::Execute() { // Save without feedback. There's no way to post e.g. a log message to the main thread at the moment. // But if saving fails, there's just a missing screenshot, which shouldn't be a big deal. png->Save(filename.getData()); SignalStop(); }
void C4StartupNetDlg::UpdateUpdateButton() { if (!fUpdateCheckPending) return; if(!pUpdateClient.isSuccess() || pUpdateClient.isBusy()) return; pUpdateClient.SetNotify(nullptr); StdCopyStrBuf versionInfo; pUpdateClient.GetVersion(&versionInfo); pUpdateClient.GetUpdateURL(&UpdateURL); #ifdef WITH_AUTOMATIC_UPDATE btnUpdate->SetVisibility(C4UpdateDlg::IsValidUpdate(versionInfo.getData())); #endif fUpdateCheckPending = false; }
StdStrBuf C4RankSystem::GetRankName(int iRank, bool fReturnLastIfOver) { if (iRank<0) return StdStrBuf(); // if a new-style ranklist is loaded, seek there if (pszRankNames) { if (iRankNum<=0) return StdStrBuf(); // overflow check if (iRank>=iRankNum*(iRankExtNum+1)) { // rank undefined: Fallback to last rank if (!fReturnLastIfOver) return StdStrBuf(); iRank = iRankNum*(iRankExtNum+1)-1; } StdStrBuf sResult; if (iRank >= iRankNum) { // extended rank composed of two parts int iExtension = iRank / iRankNum - 1; iRank = iRank % iRankNum; sResult.Format(pszRankExtensions[iExtension], pszRankNames[iRank]); } else { // simple rank sResult.Ref(pszRankNames[iRank]); } return sResult; } #ifdef _WIN32 // old-style registry fallback while (iRank>=0) { char keyname[30]; StdCopyStrBuf rankname; sprintf(keyname,"Rank%03d",iRank+1); rankname = GetRegistryString(Register,keyname); if (!rankname.isNull()) return rankname; if (!fReturnLastIfOver) return StdStrBuf(); --iRank; } #endif return StdStrBuf(); }
bool C4Console::FileNew() { StdCopyStrBuf filename; #ifdef WITH_QT_EDITOR bool host_in_network = false; if (!C4ConsoleGUI::CreateNewScenario(&filename, &host_in_network)) return false; Application.ClearCommandLine(); ::Config.Developer.AddRecentlyEditedScenario(filename.getData()); if (host_in_network) { Game.NetworkActive = true; Game.fLobby = true; } Application.OpenGame(filename.getData()); return true; #endif // Not implemented return false; }
bool RestoreWindowPosition(HWND hwnd, const char *szWindowName, const char *szSubKey, bool fHidden) { char buffer2[5]; int x,y,wdt,hgt; bool fSetSize=true; StdCopyStrBuf regstr = GetRegistryString(szSubKey,szWindowName); // No position stored: cannot restore if (regstr.isNull()) return false; if (regstr == "Maximized") return !!ShowWindow(hwnd,SW_MAXIMIZE | SW_NORMAL); if (regstr == "Minimized") return !!ShowWindow(hwnd,SW_MINIMIZE | SW_NORMAL); SCopySegment(regstr.getData(),0,buffer2,',',4); sscanf(buffer2,"%i",&x); SCopySegment(regstr.getData(),1,buffer2,',',4); sscanf(buffer2,"%i",&y); if (SCopySegment(regstr.getData(),2,buffer2,',',4)) sscanf(buffer2,"%i",&wdt); else fSetSize=false; if (SCopySegment(regstr.getData(),3,buffer2,',',4)) sscanf(buffer2,"%i",&hgt); else fSetSize=false; if (!fSetSize) { RECT winpos; if (!GetWindowRect(hwnd,&winpos)) return false; wdt=winpos.right-winpos.left; hgt=winpos.bottom-winpos.top; } // Move window WINDOWPLACEMENT wp; memset(&wp, 0, sizeof(WINDOWPLACEMENT)); wp.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hwnd, &wp); RECT normalpos; normalpos.left = x; normalpos.right = wdt + x; normalpos.top = y; normalpos.bottom = hgt + y; wp.rcNormalPosition = normalpos; if (SetWindowPlacement(hwnd, &wp)) return false; // Hide window if (fHidden) return !!ShowWindow(hwnd, SW_HIDE); // Show window return !!ShowWindow(hwnd, SW_NORMAL); }
bool StdCompilerConfigRead::Name(const char *szName) { // Adjust key name for lists StdCopyStrBuf sName; if (pKey->LastChildName == szName) sName.Format("%s%d", szName, (int)++pKey->subindex); else { sName = szName; pKey->LastChildName = szName; } bool fFound = true; // Try to open registry key HKEY hSubKey; DWORD dwType = 0; if (RegOpenKeyExW(pKey->Handle, sName.GetWideChar(), 0, KEY_READ, &hSubKey) != ERROR_SUCCESS) { hSubKey = 0; // Try to query value (exists?) if (RegQueryValueExW(pKey->Handle, sName.GetWideChar(), 0, &dwType, NULL, NULL) != ERROR_SUCCESS) fFound = false; } // Push new subkey on the stack Key *pnKey = new Key(); pnKey->Handle = hSubKey; pnKey->Name = sName; pnKey->subindex = 0; pnKey->Parent = pKey; pnKey->Virtual = !fFound; pnKey->Type = dwType; pKey = pnKey; iDepth++; // Last string reset LastString.Clear(); return fFound; }
bool C4Shader::Refresh(const char *szWhat, const char **szUniforms) { // Find a slice where the source file has updated ShaderSliceList::iterator pSlice; for (pSlice = FragmentSlices.begin(); pSlice != FragmentSlices.end(); pSlice++) if (pSlice->Source.getLength() && FileExists(pSlice->Source.getData()) && FileTime(pSlice->Source.getData()) > pSlice->SourceTime) break; if (pSlice == FragmentSlices.end()) return true; StdCopyStrBuf Source = pSlice->Source; // Okay, remove all slices that came from this file ShaderSliceList::iterator pNext; for (; pSlice != FragmentSlices.end(); pSlice = pNext) { pNext = pSlice; pNext++; if (SEqual(pSlice->Source.getData(), Source.getData())) FragmentSlices.erase(pSlice); } // Load new shader char szParentPath[_MAX_PATH+1]; C4Group Group; StdStrBuf Shader; GetParentPath(Source.getData(),szParentPath); if(!Group.Open(szParentPath) || !Group.LoadEntryString(GetFilename(Source.getData()),&Shader) || !Group.Close()) { ShaderLogF(" gl: Failed to refresh %s shader from %s!", szWhat, Source.getData()); return Refresh(szWhat, szUniforms); } // Load slices int iSourceTime = FileTime(Source.getData()); StdStrBuf WhatSrc = FormatString("file %s", Config.AtRelativePath(Source.getData())); AddFragmentSlices(WhatSrc.getData(), Shader.getData(), Source.getData(), iSourceTime); // Reinitialise if (!Init(szWhat, szUniforms)) return false; // Retry return Refresh(szWhat, szUniforms); }
int C4RankSystem::Init(const char *szRegister, const char *szDefRanks, int iRankBase) { // Init SCopy(szRegister,Register,256); RankBase=iRankBase; // Check registry for present rank names and set defaults #ifdef _WIN32 int crank=0; char keyname[30]; StdCopyStrBuf rankname; bool Checking=true; while (Checking) { sprintf(keyname,"Rank%03d",crank+1); rankname = GetRegistryString(Register,keyname); if (!rankname.isNull()) { // Rank present crank++; } else { // Rank not defined, check for default rankname.AppendChars('\0', C4MaxName); if (SCopySegment(szDefRanks,crank,rankname.getMData(),'|',C4MaxName) && SetRegistryString(Register,keyname,rankname.getData())) crank++; else Checking=false; } } return crank; #else // clear any loaded rank names Clear(); if (!szDefRanks) return 0; // make a copy szRankNames = new char[strlen(szDefRanks) + 1]; strcpy (szRankNames, szDefRanks); // split into substrings by replacing the | with zeros for (char * p = szRankNames; *p; ++p) if (*p == '|') { *p = 0; ++iRankNum; } ++ iRankNum; // The last rank is already terminated by zero // build a list of substrings pszRankNames = new char *[iRankNum]; char * p = szRankNames; for (int i = 0; i < iRankNum; ++i) { pszRankNames[i] = p; p += strlen(p) + 1; } return iRankNum; #endif }
void C4StartupMainDlg::OnPlayerSelContextAddPlr( C4GUI::Element *pTarget, const StdCopyStrBuf &rsFilename) { SAddModule(Config.General.Participants, rsFilename.getData()); UpdateParticipants(); }
bool C4MusicFileOgg::Init(const char *strFile) { // Clear previous Clear(); // Base init file if (!C4MusicFile::Init(strFile)) return false; // Initial file loading // Currently, the whole compressed file is kept in memory because reading/seeking inside C4Group is problematic. Uncompress while playing. // This uses about 50MB of RAM (for ala's music pack) and increases startup time a bit. // Later, this could be replaced with proper random access in c4group. Either replacing the file format or e.g. storing the current zlib state here // and then updating callbacks.read/seek/close/tell_func to read data from the group directly as needed char *file_contents; size_t file_size; if (!C4Group_ReadFile(FileName, &file_contents, &file_size)) return false; data.SetOwnedData((BYTE *)file_contents, file_size); // Prepare ogg reader vorbis_info* info; memset(&ogg_file, 0, sizeof(ogg_file)); ov_callbacks callbacks; callbacks.read_func = &::C4SoundLoaders::VorbisLoader::read_func; callbacks.seek_func = &::C4SoundLoaders::VorbisLoader::seek_func; callbacks.close_func = &::C4SoundLoaders::VorbisLoader::close_func; callbacks.tell_func = &::C4SoundLoaders::VorbisLoader::tell_func; // open using callbacks if (ov_open_callbacks(&data, &ogg_file, NULL, 0, callbacks) != 0) { ov_clear(&ogg_file); return false; } // get information about music info = ov_info(&ogg_file, -1); if (info->channels == 1) ogg_info.format = AL_FORMAT_MONO16; else ogg_info.format = AL_FORMAT_STEREO16; ogg_info.sample_rate = info->rate; ogg_info.sample_length = ov_time_total(&ogg_file, -1) / 1000.0; // Get categories from ogg comment header vorbis_comment *comment = ov_comment(&ogg_file, -1); const char *comment_id = "COMMENT="; int comment_id_len = strlen(comment_id); for (int i = 0; i < comment->comments; ++i) { if (comment->comment_lengths[i] > comment_id_len) { if (SEqual2NoCase(comment->user_comments[i], comment_id, comment_id_len)) { // Add all categories delimeted by ';' const char *categories_string = comment->user_comments[i] + comment_id_len; for (;;) { int delimeter = SCharPos(';', categories_string); StdCopyStrBuf category; category.Copy(categories_string, delimeter >= 0 ? delimeter : SLen(categories_string)); categories.push_back(category); if (delimeter < 0) break; categories_string += delimeter+1; } } } } // mark successfully loaded return loaded = true; }
void C4Network2ClientDlg::UpdateText() { // begin updating (clears previous text) BeginUpdateText(); // get core const C4Client *pClient = Game.Clients.getClientByID(iClientID); if (!pClient) { // client ID unknown AddLineFmt(LoadResStr("IDS_NET_CLIENT_INFO_UNKNOWNID"), iClientID); } else { // get client (may be nullptr for local info) C4Network2Client *pNetClient = pClient->getNetClient(); // show some info StdCopyStrBuf strInfo; if (!pClient->isActivated()) { strInfo.Append(LoadResStr("IDS_MSG_INACTIVE")); strInfo.Append(" "); } if (pClient->isLocal()) { strInfo.Append(LoadResStr("IDS_MSG_LOCAL")); strInfo.Append(" "); } strInfo.AppendFormat("%s %s (ID #%d)%s", LoadResStr(pClient->isHost() ? "IDS_MSG_HOST" : "IDS_MSG_CLIENT"), pClient->getName(), iClientID, ::Network.isHost() && pNetClient && !pNetClient->isReady() ? " (!ack)" : ""); AddLine(strInfo.getData()); // show addresses int iCnt; if ((iCnt=pNetClient->getAddrCnt())) { AddLine(LoadResStr("IDS_NET_CLIENT_INFO_ADDRESSES")); for (int i=0; i<iCnt; ++i) { C4Network2Address addr = pNetClient->getAddr(i); AddLineFmt(" %d: %s", i, // adress index addr.toString().getData()); } } else AddLine(LoadResStr("IDS_NET_CLIENT_INFO_NOADDRESSES")); // show connection if (pNetClient) { // connections if (pNetClient->isConnected()) { AddLineFmt(LoadResStr("IDS_NET_CLIENT_INFO_CONNECTIONS"), pNetClient->getMsgConn() == pNetClient->getDataConn() ? "Msg/Data" : "Msg", ::Network.NetIO.getNetIOName(pNetClient->getMsgConn()->getNetClass()), pNetClient->getMsgConn()->getPeerAddr().ToString().getData(), pNetClient->getMsgConn()->getPingTime()); if (pNetClient->getMsgConn() != pNetClient->getDataConn()) AddLineFmt(LoadResStr("IDS_NET_CLIENT_INFO_CONNDATA"), ::Network.NetIO.getNetIOName(pNetClient->getDataConn()->getNetClass()), pNetClient->getDataConn()->getPeerAddr().ToString().getData(), pNetClient->getDataConn()->getPingTime()); } else AddLine(LoadResStr("IDS_NET_CLIENT_INFO_NOCONNECTIONS")); } } // update done EndUpdateText(); }