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 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(); }
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); }
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; }
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(); }
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(); }