CMainRoot::CMainRoot() { #ifdef _DEBUG if(LoadRenderSystemLibrary("Plugins\\RenderSystemDX9d.dll") == true) #else if(LoadRenderSystemLibrary("Plugins\\RenderSystemDX9.dll") == true) #endif { // # InitLua //InitLua(CUICombo::m_pLuaState); // ---- // UI Theme std::string strThemeFilename = "Data\\UI\\UIStyle.xml"; // ---- GetStyleMgr().Create(strThemeFilename.c_str()); // ---- // # UI Font std::string strLanguage = IniGetStr("GameUI.cfg", "UIConfig", "language"); std::string strFont1 = IniGetStr("Font.cfg",strLanguage.c_str(), "font1"); // ---- UIGraph::getInstance().initFont(strFont1.c_str(),13); // ---- // # Create UI std::string strUIFilename = IniGetStr("GameUI.cfg", "UIConfig", "file"); // ---- CDlgMain::getInstance().create(strUIFilename.c_str(), "IDD_MAIN"); // ---- // # Load UI Language setUILanguage(strLanguage); // ---- // # (leo123) : i think next variables must be in register // # Create Render System Window int nWidth = IniGetInt("Game.cfg", "display", "width", 800); int nHeight = IniGetInt("Game.cfg", "display", "height", 500); // ---- CreateRenderWindow(GAME_TITLE_W, nWidth, nHeight); // # Common Materials //CRenderNodeMgr::getInstance().loadRenderNode("Data\\Common.mat.csv",NULL); //CRenderNodeMgr::getInstance().loadRenderNode("EngineRes\\Common.mat.csv",NULL); //DirectoryList("EngineRes\\shader",MATERIAL_GEOMETRY); DirectoryList("EngineRes\\shader\\geometry",RF_GEOMETRY); DirectoryList("EngineRes\\shader\\glow",RF_GLOW); DirectoryList("EngineRes\\shader\\bump",RF_BUMP); DirectoryList("EngineRes\\shader\\post-processing",RF_GEOMETRY); DirectoryList("EngineRes\\shader\\ui",RF_GEOMETRY); //DirectoryList("Data\\shader\\"); // ---- // # NetWork NETWORK.SetHWND (m_hWnd); NETWORK.SetWinMsgNum(WM_GM_JOIN_CLIENT_MSG_PROC); NETWORK.SetProtocolCore(ProtocolCore); } }
void n2e_EditSelectionInit(LPCWSTR lpSection, const int iDefaultSection, const int iIndicator, LPCWSTR lpAlphaSetting, const int iDefaultAlpha, LPCWSTR lpLineAlphaSetting, const int iDefaultLineAlpha, LPCWSTR lpColorSetting, const COLORREF iDefaultColor, LPCWSTR lpUnderSetting, const int iDefaultUnder) { const int indi_style = IniGetInt(N2E_INI_SECTION, lpSection, iDefaultSection); if (indi_style >= 0) { SendMessage(hwndEdit, SCI_INDICSETSTYLE, iIndicator, indi_style); SendMessage(hwndEdit, SCI_INDICSETALPHA, iIndicator, IniGetInt(N2E_INI_SECTION, lpAlphaSetting, iDefaultAlpha)); SendMessage(hwndEdit, SCI_INDICSETOUTLINEALPHA, iIndicator, IniGetInt(N2E_INI_SECTION, lpLineAlphaSetting, iDefaultLineAlpha)); SendMessage(hwndEdit, SCI_INDICSETFORE, iIndicator, IniGetInt(N2E_INI_SECTION, lpColorSetting, iDefaultColor)); SendMessage(hwndEdit, SCI_INDICSETUNDER, iIndicator, IniGetInt(N2E_INI_SECTION, lpUnderSetting, iDefaultUnder)); } }
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == SC_CLOSE && ! IniGetInt (INI_FILE, "ExitOnX", 0) && (TRAY_ICON || HIDE_ICON)) { SendMessage (WM_SYSCOMMAND, SC_MINIMIZE, 0); return; } CMDIFrameWnd::OnSysCommand (nID, lParam); }
void PreLaunchCallback ( int launch_type) { // Stall if we've just booted (within 5 minutes of Windows starting) if (GetTickCount () < 300000 && launch_type == LD_CONTINUE) { int delay; delay = IniGetInt (INI_FILE, "BootDelay", 90); delay -= GetTickCount () / 1000; if (delay > 0) Sleep (delay * 1000); } }
BOOL CPrime95App::InitInstance() { int orig_cmdShow; int named_ini_files = -1; int torture_test = 0; char *p; // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. //SetRegistryKey(_T("GIMPS")); //LoadStdProfileSettings(0); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MDITYPE, RUNTIME_CLASS(CPrime95Doc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CPrime95View)); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); // Init our view mutexes gwmutex_init (&VIEW_MUTEX); gwmutex_init (&VIEW_LINES_MUTEX); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME)) { delete pMainFrame; return FALSE; } m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line orig_cmdShow = m_nCmdShow; if (!ProcessShellCommand(cmdInfo)) return FALSE; /* Change the working directory to the same directory that */ /* the executable is located. This is especially important */ /* for running prime95 as a Windows 95 service */ { char buf[256]; GetModuleFileName (NULL, buf, sizeof (buf)); strrchr (buf, '\\')[1] = 0; _chdir (buf); } /* Initialize gwnum call back routines. Using callback routines lets the */ /* gwnum library have a nice clean interface for users that do not need */ /* additional functionality that only prime95 uses. */ StopCheckRoutine = stopCheck; OutputBothRoutine = OutputBoth; /* NT services are not passed command line arguments. In this case we */ /* encode the -An information in the NT service name. */ if (NTSERVICENAME[0] && NTSERVICENAME[15] == '-') named_ini_files = atoi (&NTSERVICENAME[16]); // Process command line switches for (p = m_lpCmdLine; *p == '//' || *p == '-'; ) { p++; switch (*p++) { // Accept a -A switch indicating an alternate set of INI files // are to be used. case 'A': case 'a': named_ini_files = 0; while (isspace (*p)) p++; while (isdigit (*p)) { named_ini_files = named_ini_files * 10 + (*p - '0'); p++; } break; // Accept a -T switch to run the torture test. case 'T': case 't': torture_test = 1; break; // Accept a -W switch indicating an alternate working directory. case 'W': case 'w': { char buf[256]; char *bufp = buf; while (isspace (*p)) p++; while (*p && !isspace (*p)) *bufp++ = *p++; *bufp = 0; _chdir (buf); } break; } // Skip whitespace between switches while (isspace (*p)) p++; } // Make sure only one copy of prime95 is running at a time. // This code is courtesy of Jeroen C. van Gelderen // I enhanced it to allow multiple copies if they are running // from different directories or use different -A switches. { char buf[256]; char *p; DWORD mutex_error_code; PSID pEveryoneSID = NULL, pAdminSID = NULL; PACL pACL = NULL; PSECURITY_DESCRIPTOR pSD = NULL; EXPLICIT_ACCESS ea[1]; SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY; SECURITY_ATTRIBUTES sa; // Turn directory name into a (likely) unique integer // Add in the -A value. Use this integer to create a mutex name. _getcwd (buf, 255); for (p = buf; *p; p++) g_MutexNum = g_MutexNum * 17 + *p; g_MutexNum += named_ini_files; sprintf (buf, "Global\\GIMPS%ld", g_MutexNum); /* Create a world access security descriptor to share the Mutex we */ /* are about to create. If we run into any troubles, assume this is */ /* a Windows 95/98/Me system and create a simple Mutex. */ // Create a well-known SID for the Everyone group. if (! AllocateAndInitializeSid ( &SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID)) goto simple_mutex; // Initialize an EXPLICIT_ACCESS structure for an ACE. // The ACE will allow the Administrators group full access to the key. ZeroMemory (&ea, sizeof (EXPLICIT_ACCESS)); ea[0].grfAccessPermissions = EVENT_ALL_ACCESS; ea[0].grfAccessMode = SET_ACCESS; ea[0].grfInheritance= NO_INHERITANCE; ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID; ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; ea[0].Trustee.ptstrName = (LPTSTR) pEveryoneSID; // Create a new ACL that contains the new ACEs. if (SetEntriesInAcl (1, ea, NULL, &pACL) != ERROR_SUCCESS) goto simple_mutex; // Initialize a security descriptor. pSD = (PSECURITY_DESCRIPTOR) LocalAlloc (LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); if (pSD == NULL) goto simple_mutex; if (! InitializeSecurityDescriptor (pSD, SECURITY_DESCRIPTOR_REVISION)) goto simple_mutex; // Add the ACL to the security descriptor. if (! SetSecurityDescriptorDacl (pSD, TRUE, pACL, FALSE)) goto simple_mutex; // Initialize a security attributes structure. sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = pSD; sa.bInheritHandle = FALSE; // Create our mutex. Windows XP uses terminal services to support user // switching. The "Global\" prefix is required so that this mutex is // is created in the global kernel objects namespace. Unfortunately, // the "\" character raises an error on Windows 95/98/Me systems. g_hMutexInst = CreateMutex ( &sa, // World access FALSE, // Not owned !! buf); // Unique name if (g_hMutexInst == NULL) simple_mutex: g_hMutexInst = CreateMutex ( NULL, // No security stuff FALSE, // Not owned !! buf+7); // Unique name mutex_error_code = GetLastError (); // Cleanup all the security structures we initialized if (pEveryoneSID) FreeSid (pEveryoneSID); if (pACL) LocalFree (pACL); if (pSD) LocalFree (pSD); // Test for failure if (g_hMutexInst == NULL) return 0; // If mutex already exists then another instance is already running if (mutex_error_code == ERROR_ALREADY_EXISTS) { HWND hwndPrevInst = 0; // Give other instance a little time to display it's main window Sleep (750); // Find the window handle EnumWindows (&MyEnumProc, (LPARAM) &hwndPrevInst); // Unhide the other instance's window if (hwndPrevInst) { ShowWindow (hwndPrevInst, SW_HIDE); ShowWindow (hwndPrevInst, SW_SHOWMINIMIZED); ShowWindow (hwndPrevInst, SW_SHOWNORMAL); } CloseHandle (g_hMutexInst); g_hMutexInst = NULL; return 0; } // Set the window user data so we can be identified by // another instance of this program. SetWindowLongPtr (m_pMainWnd->m_hWnd, GWLP_USERDATA, (LONG_PTR) g_MutexNum); } /* Cache icon handles to work around Windows deadlocking bug */ ICON_IDLE = LoadIcon (IDI_YELLOW_ICON); ICON_WORKING = LoadIcon (IDR_MAINFRAME); /* Name and read the INI files. Perform some other startup initializations. */ nameAndReadIniFiles (named_ini_files); initCommCode (); /* Before processing the INI file, hide and/or position the */ /* main window so that we can display error messages */ m_pMainWnd->SetWindowText ("Prime95"); WINDOWPLACEMENT wp; m_pMainWnd->GetWindowPlacement (&wp); int left = IniGetInt (INI_FILE, "Left", 0); int top = IniGetInt (INI_FILE, "Top", 0); int right = IniGetInt (INI_FILE, "Right", 0); int bottom = IniGetInt (INI_FILE, "Bottom", 0); if (right + left + top + bottom != 0) { wp.rcNormalPosition.left = left; wp.rcNormalPosition.top = top; wp.rcNormalPosition.right = right; wp.rcNormalPosition.bottom = bottom; } wp.showCmd = HIDE_ICON ? SW_HIDE : SW_SHOWMINIMIZED; m_pMainWnd->SetWindowPlacement (&wp); /* Now show the main window and post initial messages */ // Put prime95 in the system tray if (TRAY_ICON) TrayMessage (NIM_ADD, "Prime95", 0); // See if we are running as a Windows95 service WINDOWS95_SERVICE = IniGetInt (INI_FILE, "Windows95Service", 0); WINDOWS95_A_SWITCH = named_ini_files; Service95 (); // Run the torture test if asked to by a command line argument if (torture_test) { m_pMainWnd->ShowWindow (orig_cmdShow); m_pMainWnd->PostMessage (WM_COMMAND, USR_TORTURE, 0); } // On first run, see if this is a stress tester. If not, step // user throught the primenet dialog boxes. else if (STRESS_TESTER == 99) { m_pMainWnd->ShowWindow (orig_cmdShow); m_pMainWnd->PostMessage (WM_COMMAND, USR_WELCOME, 0); } // Take stress testers straight to the torture dialog box else if (STRESS_TESTER) { m_pMainWnd->ShowWindow (orig_cmdShow); m_pMainWnd->PostMessage (WM_COMMAND, IDM_TORTURE, 0); } // Auto-continue if there is any work to do. else if (USE_PRIMENET || WELL_BEHAVED_WORK || WORKTODO_COUNT) { m_pMainWnd->PostMessage (WM_COMMAND, IDM_CONTINUE, 0); } // Otherwise, show the window else if (!HIDE_ICON) { m_pMainWnd->ShowWindow (orig_cmdShow); ChangeIcon (MAIN_THREAD_NUM, IDLE_ICON); } // Initialization complete return TRUE; }
void linuxContinue ( char *error_message, int thread_num, /* Specific worker to launch or */ /* special value ALL_WORKERS */ int wait_flag) { #ifdef __linux__ #define PROCNAME "/proc/%d/exe" #endif #ifdef __FreeBSD__ #define PROCNAME "/proc/%d/file" #endif pid_t my_pid, running_pid; char filename[30]; int fd; struct stat filedata; ino_t inode1, inode2; /* Compare this process' ID and the pid from the INI file */ my_pid = getpid (); openIniFile (LOCALINI_FILE, 1); running_pid = IniGetInt (LOCALINI_FILE, "Pid", 0); if (running_pid == 0 || my_pid == running_pid) goto ok; #if defined (__APPLE__) || defined (__HAIKU__) goto ok; #elif defined (__OS2__) { USHORT handle1 = 0, handle2 = 0; unsigned char buf[0x2000]; if( !DosQuerySysState(0x01, 0, 0, 0, (PCHAR)buf, 0x2000) ) { PQPROCESS p = ((PQTOPLEVEL)buf)->procdata; while(p && p->rectype == 1) { if( p->pid == running_pid ) handle1 = p->hndmod; if( p->pid == my_pid ) handle2 = p->hndmod; p = (PQPROCESS)(p->threads + p->threadcnt); } if( handle1 != handle2 ) goto ok; } } #else /* See if the two pids are running the same executable */ sprintf (filename, PROCNAME, my_pid); fd = _open (filename, _O_RDONLY); if (fd < 0) goto ok; fstat (fd, &filedata); inode1 = filedata.st_ino; _close (fd); sprintf (filename, PROCNAME, running_pid); fd = _open (filename, _O_RDONLY); if (fd < 0) goto ok; fstat (fd, &filedata); inode2 = filedata.st_ino; _close (fd); if (inode1 != inode2) goto ok; #endif /* The two pids are running the same executable, raise an error and return */ if (error_message != NULL) printf ("%s", error_message); return; /* All is OK, save our pid, run, then delete our pid */ ok: IniWriteInt (LOCALINI_FILE, "Pid", my_pid); LaunchWorkerThreads (thread_num, wait_flag); if (wait_flag) IniWriteInt (LOCALINI_FILE, "Pid", 0); }
int main ( int argc, char *argv[]) { char buf[256]; int named_ini_files = -1; int contact_server = 0; int torture_test = 0; int i, nice_level; char *p; /* catch termination signals */ (void)signal(SIGTERM, sigterm_handler); (void)signal(SIGINT, sigterm_handler); /* No buffering of output */ setvbuf (stdout, NULL, _IONBF, 0); /* Change to the executable's directory */ /* NOTE: This only changes the working directory if the user typed */ /* in a full path to the executable (as opposed to finding it on the PATH) */ strcpy (buf, argv[0]); p = strrchr (buf, '/'); if (p != NULL) { *p = 0; (void) _chdir (buf); } /* Initialize gwnum call back routines. Using callback routines lets the */ /* gwnum library have a nice clean interface for users that do not need */ /* additional functionality that only prime95 uses. */ StopCheckRoutine = stopCheck; OutputBothRoutine = OutputBoth; /* Process command line switches */ for (i = 1; i < argc; i++) { p = argv[i]; if (*p++ != '-') break; switch (*p++) { /* Accept a -A switch indicating an alternate set of INI files */ /* are to be used. */ case 'A': case 'a': named_ini_files = 0; while (isspace (*p)) p++; while (isdigit (*p)) { named_ini_files = named_ini_files * 10 + (*p - '0'); p++; } break; /* -C - contact the server now, then exit */ case 'C': case 'c': contact_server = 1; VERBOSE = TRUE; NO_GUI = FALSE; break; /* -D - debug */ case 'D': case 'd': VERBOSE = TRUE; NO_GUI = FALSE; break; /* -H - help */ case 'H': case 'h': case '?': goto usage; /* -M - Menu */ case 'M': case 'm': MENUING = 1; NO_GUI = FALSE; break; /* -S - status */ case 'S': case 's': MENUING = 2; NO_GUI = FALSE; break; /* -T - Torture test */ case 'T': case 't': torture_test = TRUE; break; /* -V - version number */ case 'V': case 'v': printf ("Mersenne Prime Test Program, Version %s.%d\n", VERSION, PORT); return (0); /* -W - use a different working directory */ case 'W': case 'w': (void) _chdir (p); break; /* Otherwise unknown switch */ default: printf ("Invalid switch\n"); goto usage; } } /* Determine the names of the INI files, read them, do other initialization. */ /* Skip the comm code initialization if we are just displaying the status */ /* or running a torture test */ nameAndReadIniFiles (named_ini_files); if (MENUING != 2 && !torture_test) initCommCode (); /* If not running a torture test, set the program to nice priority. */ /* Technically, this is not necessary since worker threads are set to */ /* the lowest possible priority. However, sysadmins might be alarmed */ /* to see a CPU intensive program not running at nice priority when */ /* executing a ps command. */ #if defined (__linux__) || defined (__APPLE__) || defined (__FreeBSD__) /* Linux/FreeBSD ranges from -20 to +19, lower values give more favorable scheduling */ nice_level = IniGetInt (INI_FILE, "Nice", 10); if (!torture_test && nice_level) { setpriority (PRIO_PROCESS, 0, nice_level); } #endif /* If running the torture test, do so now. */ if (torture_test) { int num_threads; VERBOSE = TRUE; NO_GUI = FALSE; num_threads = IniGetInt (INI_FILE, "TortureThreads", NUM_CPUS * CPU_HYPERTHREADS); LaunchTortureTest (num_threads, TRUE); } /* If this is a stress tester, then turn on menuing. */ else if (IniGetInt (INI_FILE, "StressTester", 99) == 1) { MENUING = 1; VERBOSE = TRUE; NO_GUI = FALSE; main_menu (); } /* On first run, get user id before contacting server */ /* for a work assignment. To make first time user more comfortable, we will */ /* display data to the screen, rather than running silently. */ else if (IniGetInt (INI_FILE, "StressTester", 99) == 99) { VERBOSE = TRUE; NO_GUI = FALSE; test_welcome (); } /* If we are to contact the server, do so now. This option lets the */ /* user create a batch file that contacts the server at regular intervals */ /* or when the ISP is contacted, etc. */ else if (contact_server) { do_manual_comm_now (); while (COMMUNICATION_THREAD) Sleep (50); } /* Bring up the main menu */ else if (MENUING == 1) main_menu (); else if (MENUING == 2) test_status(); /* Continue testing, return when worker threads exit. */ else { linuxContinue ("Another mprime is already running!\n", ALL_WORKERS, TRUE); } /* Write the worktodo file in case the WELL_BEHAVED_WORK flag caused us */ /* to delay writing the file. */ writeWorkToDoFile (TRUE); /* All done */ return (0); /* Invalid args message */ usage: printf ("Usage: mprime [-cdhmstv] [-aN] [-wDIR]\n"); printf ("-c\tContact the PrimeNet server, then exit.\n"); printf ("-d\tPrint detailed information to stdout.\n"); printf ("-h\tPrint this.\n"); printf ("-m\tMenu to configure mprime.\n"); printf ("-s\tDisplay status.\n"); printf ("-t\tRun the torture test.\n"); printf ("-v\tPrint the version number.\n"); printf ("-aN\tUse an alternate set of INI and output files (obsolete).\n"); printf ("-wDIR\tRun from a different working directory.\n"); printf ("\n"); return (1); }
int LoadPrimeNet (void) { static int RAS_NOT_AVAILABLE = 0; static HMODULE HRAS = 0; static DWORD (APIENTRY *RAS_ENUM)(LPRASCONNA, LPDWORD, LPDWORD); static DWORD (APIENTRY *RAS_STAT)(HRASCONN, LPRASCONNSTATUSA); RASCONN connections[10]; DWORD bufsize; DWORD i, num_connections; DWORD ret; /* Special handling prior to first primenet call. */ /* Init Winsock, requesting version 1.1 */ if (! SOCKETS_INITIALIZED) { static WSADATA zz; int res; res = WSAStartup (MAKEWORD (1, 1), &zz); if (res != 0) { char buf[80]; sprintf (buf, "ERROR: Winsock initialization returned %d.\n", res); OutputStr (COMM_THREAD_NUM, buf); return (FALSE); } SOCKETS_INITIALIZED = 1; } /* If we're not using a dial-up connection, let primenet try */ /* to contact the server. */ if (!DIAL_UP) return (TRUE); /* Since Windows 95 can bring up a "Connect To" dialog box */ /* on any call to primenet, we try to make sure we are */ /* already connected before we call primenet. Otherwise, if */ /* no one is at the computer to respond to the "Connect To" */ /* dialog, the thread hangs until some one does respond. */ /* RAS calls, see below, is no longer the MS-prefered method of detecting */ /* an Internet connection. Starting in version 22.10 we offer a way for */ /* for users to use the prefered wininet.dll method. */ /* InternetGetConnectedState should return FALSE if the modem is not */ /* connected to the Internet. */ /* Starting in version 25.1, this became the default detection method. */ if (IniGetInt (INI_FILE, "AlternateModemDetection", 1)) { DWORD flags; if (InternetGetConnectedState (&flags, 0)) return (TRUE); goto no_modem_connection; } // Unfortunately, the RASAPI32.DLL is not installed on every // system. We must load it dynamically. If the RAS library // is not found, let primenet.dll try to contact the server. if (RAS_NOT_AVAILABLE) return (TRUE); if (HRAS == 0) { RAS_NOT_AVAILABLE = 1; HRAS = LoadLibrary ("rasapi32.dll"); if (HRAS == 0) return (TRUE); RAS_ENUM = (DWORD (APIENTRY *)(LPRASCONNA, LPDWORD, LPDWORD)) GetProcAddress (HRAS, "RasEnumConnectionsA"); if (RAS_ENUM == NULL) return (TRUE); RAS_STAT = (DWORD (APIENTRY *)(HRASCONN, LPRASCONNSTATUSA)) GetProcAddress (HRAS, "RasGetConnectStatusA"); if (RAS_STAT == NULL) return (TRUE); RAS_NOT_AVAILABLE = 0; } // Call RAS to see if there are any active connections to the Internet connections[0].dwSize = sizeof (RASCONN); bufsize = sizeof (connections); ret = (*RAS_ENUM) ((RASCONN *) &connections, &bufsize, &num_connections); // If RAS returns an error who knows what went wrong. // Let primenet try to connect anyway. if (ret) return (TRUE); // See if any of these connections are really connected for (i = 0; i < num_connections; i++) { RASCONNSTATUS status; status.dwSize = sizeof (RASCONNSTATUS); ret = (*RAS_STAT) (connections[i].hrasconn, &status); if (ret) continue; if (status.rasconnstate == RASCS_Connected) return (TRUE); } // Print error message if no there are no connections no_modem_connection: OutputStr (COMM_THREAD_NUM, "Dial-up connection not active.\n"); return (FALSE); }
void rangeStatusMessage ( char *buf, unsigned int buflen) /* Originally coded for a 2000 character buffer */ { unsigned int tnum, ll_cnt, lines_per_worker; double prob, est; char *orig_buf; /* Just in case the user hand added work to the worktodo file, reread it */ /* now if the worker threads and communication threads are not active. */ if (! WORKER_THREADS_ACTIVE && !COMMUNICATION_THREAD) readIniFiles (); /* Init. Default is 32 lines in a 2000 character buffer */ lines_per_worker = (unsigned int) IniGetInt (INI_FILE, "StatusLines", buflen / 62) / NUM_WORKER_THREADS; if (lines_per_worker < 3) lines_per_worker = 3; orig_buf = buf; ll_cnt = 0; prob = 0.0; strcpy (buf, STAT0); buf += strlen (buf); /* Loop over all worker threads */ for (tnum = 0; tnum < NUM_WORKER_THREADS; tnum++) { struct work_unit *w; unsigned int lines_output; int truncated_status_msg; /* Init line formatting info */ lines_output = 0; truncated_status_msg = FALSE; /* Output thread id */ if (NUM_WORKER_THREADS > 1) { sprintf (buf, "[Worker thread #%d]\n", tnum+1); buf += strlen (buf); lines_output++; } /* Loop over all work units */ w = NULL; est = 0.0; for ( ; ; ) { time_t this_time; char timebuf[80]; unsigned int bits; /* Read the next line of the work file */ w = getNextWorkToDoLine (tnum, w, SHORT_TERM_USE); if (w == NULL) break; if (w->work_type == WORK_NONE) continue; /* If testing then adjust our probabilities */ /* This assumes our error rate is roughly 1.8% */ bits = (unsigned int) w->sieve_depth; if (bits < 32) bits = 32; if (w->work_type == WORK_TEST) { ll_cnt++; if (w->pminus1ed) prob += (double) ((bits - 1) * 1.803) / w->n; else prob += (double) ((bits - 1) * 1.733) / w->n; } if (w->work_type == WORK_DBLCHK) { ll_cnt++; if (w->pminus1ed) prob += (double) ((bits - 1) * 1.803 * ERROR_RATE) / w->n; else prob += (double) ((bits - 1) * 1.733 * ERROR_RATE) / w->n; } /* Adjust our time estimate */ est += work_estimate (tnum, w); /* Stop adding worktodo lines if buffer is full. We must still loop */ /* through the worktodo lines to decrement the in-use counters. */ if ((unsigned int) (buf - orig_buf) >= buflen - 200 || lines_output >= lines_per_worker-1) { if (! truncated_status_msg) { strcpy (buf, "More...\n"); buf += strlen (buf); truncated_status_msg = TRUE; } continue; } /* Add the exponent to the output message */ gw_as_string (buf, w->k, w->b, w->n, w->c); buf += strlen (buf); if (w->work_type == WORK_PRP && w->known_factors) { strcpy (buf, "/known_factors"); buf += strlen (buf); } strcpy (buf, ", "); buf += strlen (buf); if (w->work_type == WORK_ECM) sprintf (buf, "ECM %d curve%s B1=%.0f", w->curves_to_do, w->curves_to_do == 1 ? "" : "s", w->B1); else if (w->work_type == WORK_PMINUS1) sprintf (buf, "P-1 B1=%.0f", w->B1); else if (w->work_type == WORK_FACTOR) sprintf (buf, "factor from 2^%d to 2^%d", (int) w->sieve_depth, (int) w->factor_to); else strcpy (buf, w->work_type == WORK_PFACTOR ? "P-1" : w->work_type == WORK_TEST || w->work_type == WORK_ADVANCEDTEST ? "Lucas-Lehmer test" : w->work_type == WORK_DBLCHK ? "Double-check" : /* w->work_type == WORK_PRP */ "PRP"); buf += strlen (buf); time (&this_time); if (est + this_time < 2147483640) { this_time += (long) est; strcpy (timebuf, ctime (&this_time)); safe_strcpy (timebuf+16, timebuf+19); } else strcpy (timebuf, "after Jan 1 2038\n"); sprintf (buf, ", %s", timebuf); buf += strlen (buf); lines_output++; } /* Format more of the message */ if (est == 0.0 && ! truncated_status_msg) { strcpy (buf, STAT3); buf += strlen (buf); } } /* Print message estimating our probability of success */ if (ll_cnt == 1) sprintf (buf+strlen(buf), STAT1a, (long) (1.0 / prob)); if (ll_cnt > 1) sprintf (buf+strlen(buf), STAT1, ll_cnt, (long) (1.0 / prob)); }