From 83312f445a392cfbe875e5ef401311b538f79079 Mon Sep 17 00:00:00 2001 From: koldo Date: Tue, 14 Jul 2009 21:28:26 +0000 Subject: [PATCH] SysInfo_demo_console: Renaming package git-svn-id: svn://ultimatepp.org/upp/trunk@1399 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- .../SysInfo demo console.upp | 12 - bazaar/SysInfo demo console/main.cpp | 255 ------------------ 2 files changed, 267 deletions(-) delete mode 100644 bazaar/SysInfo demo console/SysInfo demo console.upp delete mode 100644 bazaar/SysInfo demo console/main.cpp diff --git a/bazaar/SysInfo demo console/SysInfo demo console.upp b/bazaar/SysInfo demo console/SysInfo demo console.upp deleted file mode 100644 index 928f6a735..000000000 --- a/bazaar/SysInfo demo console/SysInfo demo console.upp +++ /dev/null @@ -1,12 +0,0 @@ -uses - Core, - SysInfo; - -file - main.cpp, - src.tpp, - srcimp.tpp; - -mainconfig - "" = ""; - diff --git a/bazaar/SysInfo demo console/main.cpp b/bazaar/SysInfo demo console/main.cpp deleted file mode 100644 index 1b235bb23..000000000 --- a/bazaar/SysInfo demo console/main.cpp +++ /dev/null @@ -1,255 +0,0 @@ -#include -#include - -using namespace Upp; - -bool end = false; - -void TestGetchar() -{ - if (end) - getchar(); -} -void Puts(String s) -{ - puts(s); - String file = AppendFileName(GetDesktopFolder(), "log"); - SaveFile(file, LoadFile(file) + "\n" + s); -} -void Test() -{ - Puts("SysInfo functions demo"); - - Puts("\nSpecial folders"); - Puts(Format("Desktop: %s", GetDesktopFolder())); - Puts(Format("Programs: %s", GetProgramsFolder())); - Puts(Format("Application Data: %s", GetAppDataFolder())); - Puts(Format("Music: %s", GetMusicFolder())); - Puts(Format("Pictures: %s", GetPicturesFolder())); - Puts(Format("Video: %s", GetVideoFolder())); - Puts(Format("Personal: %s", GetPersonalFolder())); - Puts(Format("Templates: %s", GetTemplatesFolder())); - Puts(Format("Download: %s", GetDownloadFolder())); -// Puts(Format("Root: %s", GetRootFolder())); - Puts(Format("Temp: %s", GetTempFolder())); - Puts(Format("Os: %s", GetOsFolder())); - Puts(Format("System: %s", GetSystemFolder())); - - Puts("\nSystem info:"); - String manufacturer, productName, version; - Date releaseDate; - int numberOfProcessors; - GetSystemInfo(manufacturer, productName, version, numberOfProcessors); - Puts(Format("System manufacturer '%s', product name '%s',\n version '%s', number of processors: %d", manufacturer, productName, version, numberOfProcessors)); - - Puts(Format("Real CPU Speed: %.3f GHz", GetCpuSpeed()/1000.)); - - Puts("Battery info"); - bool present; - //int designCapacity,lastFullCapacity; - //String batVendor, type, model, serial; - if (!GetBatteryInfo(present/*, designCapacity, lastFullCapacity, batVendor, type, model, serial*/)) - Puts("There is no battery"); - else { - //Puts(Format("Vendor: %s, Type: %s, Model: %s, Serial: %s", batVendor, type, model, serial)); - //Puts(Format("Design capacity: %d mAh, Last full capacity: %d mAh", designCapacity, lastFullCapacity)); - if (!present) - Puts("Battery not installed"); - else { - bool discharging; - int percentage, remainingMin; - GetBatteryStatus(discharging, percentage, remainingMin); - Puts(Format("Working with battery: %s, Percentage: %d%%, Remaining: %d min", discharging ? "yes": "no", percentage, remainingMin)); - } - } - String biosVersion; - Date biosReleaseDate; - GetBiosInfo(biosVersion, biosReleaseDate); - Puts(Format("Bios version '%s',\n release date '%s'", biosVersion, AsString(biosReleaseDate))); - String vendor, identifier, architecture; - int speed; - for (int i = 0; i < numberOfProcessors; ++i) { - GetProcessorInfo(i, vendor, identifier, architecture, speed); - Puts(Format("Processor #%d: Vendor '%s',\n identifier '%s',\n architecture '%s', speed %d MHz", i, vendor, identifier, architecture, speed)); - } - Puts("\nPress enter to continue..."); TestGetchar(); - - Puts("\nMemory info:"); - int memoryLoad; - uint64 totalPhys, freePhys, totalPageFile, freePageFile, totalVirtual, freeVirtual; - if (!GetMemoryInfo(memoryLoad, totalPhys, freePhys, totalPageFile, freePageFile, totalVirtual, freeVirtual)) - Puts("Impossible to get memory information"); - else { - Puts(Format("Percent of memory in use: %d%c", memoryLoad, '%')); - Puts(Format("Total physical memory: %s bytes (%s)", Format64(totalPhys), BytesToKMGT(totalPhys))); - Puts(Format("Free physical memory: %s bytes (%s)", Format64(freePhys), BytesToKMGT(freePhys))); - Puts(Format("Total paging file: %s bytes (%s)", Format64(totalPageFile), BytesToKMGT(totalPageFile))); - Puts(Format("Free paging file: %s bytes (%s)", Format64(freePageFile), BytesToKMGT(freePageFile))); - Puts(Format("Total virtual memory: %s bytes (%s)", Format64(totalVirtual), BytesToKMGT(totalVirtual))); - Puts(Format("Free virtual memory: %s bytes (%s)", Format64(freeVirtual), BytesToKMGT(freeVirtual))); - } - Puts("\nOs info:"); - String kernel, kerVersion, kerArchitecture, distro, distVersion, desktop, deskVersion; - if (!GetOsInfo(kernel, kerVersion, kerArchitecture, distro, distVersion, desktop, deskVersion)) - Puts("Error getting Os info"); - else { - Puts(Format("Kernel: %s, version: %s,\n architecture: %s", kernel, kerVersion, kerArchitecture)); - Puts(Format("Distro: %s, version: %s", distro, distVersion, desktop, deskVersion)); - Puts(Format("Desktop: %s, version: %s", desktop, deskVersion)); - } - String compiler, date; - int compilerVersion; - GetCompilerInfo(compiler, compilerVersion, date); - Puts(Format("\nProgram compiled with %s version %d. Compilation date: %s", compiler, compilerVersion, date)); - - Puts("\nDefault exes info:"); - const char *ext[] = {".html", ".doc", ".png", ".pdf", ".txt", ".xyz", ""}; - for (int i = 0; *ext[i] != 0; ++i) - Puts(Format("Default program for '%s' is '%s'", ext[i], GetExtExecutable(ext[i]))); - - Puts("\nPress enter to continue..."); TestGetchar(); - - Puts("\nDrives list:"); - Array drives; - drives = GetDriveList(); - for (int i = 0; i < drives.GetCount(); ++i) { - Puts(Format("Drive path:'%s'", drives[i])); - String type, volume, fileSystem; - //uint64 serial; - int maxName; - bool mounted = GetDriveInformation(drives[i], type, volume, /*serial,*/ maxName, fileSystem); - if (mounted) { - Puts(Format(" Type: '%s', Volume: '%s', "/*Serial: %0n,*/"\n MaxName: %d, File System: %s", type, volume, /*serial, */maxName, fileSystem)); - uint64 freeBytesUser, totalBytesUser, totalFreeBytes; - if(!GetDriveSpace(drives[i], freeBytesUser, totalBytesUser, totalFreeBytes)) - Puts(" Mounted but no access to drive"); - else { - Puts(Format(" Free Bytes User: %s (%s)", Format64(freeBytesUser), BytesToKMGT(freeBytesUser))); - Puts(Format(" Total Bytes User: %s (%s), Total Free Bytes: %s (%s)", Format64(totalBytesUser), BytesToKMGT(totalBytesUser), Format64(totalFreeBytes), BytesToKMGT(totalFreeBytes))); - } - } else - Puts (" Not mounted"); - } - Puts("\nOther Info:"); - int id = GetProcessId(); - Puts(Format("Process Id: %d", id)); - Puts(Format("Process name: '%s'", GetProcessName(id))); - Puts(Format("Process file name: '%s'", GetProcessFileName(id))); - int priority = GetProcessPriority(id); - Puts(Format("Process priority is: %s", priority >= 0? AsString(priority): "Not accesible")); - Puts(Format("Now changed to high priority: %s", SetProcessPriority(id, 8)? "Yes": "No")); - priority = GetProcessPriority(id); - Puts(Format("Process priority is: %s", priority >= 0? AsString(priority): "Not accesible")); - - Window_SaveCapture(0, AppendFileName(GetDesktopFolder(), "Desktop")); - Puts ("Screenshot saved in " + AppendFileName(GetDesktopFolder(), "Desktop")); - - Puts("\nLaunch file 'test.txt':"); - String fileTest = AppendFileName(GetTempFolder(), "test.txt"); - String strTest = "\nIf modify 'test.txt' it will ask you to save or not the file" - "\nIf you answer Yes or No the program will be terminated" - "\nIf you answer Cancel or wait more than 2 seconds the program will be killed" - "\nClick enter in the command window to continue"; - SaveFile(fileTest, "This is a test" + strTest); - Puts(strTest); - - LaunchFile(fileTest); - { - TimeStop t; - long windowId; - while(-1 == (windowId = GetWindowIdFromCaption("test.txt", false))) { - if (t.Elapsed() > 10000) - break; - } - if (windowId != -1) { - Sleep(1000); - long left, top, right, bottom; - Window_GetRect(windowId, left, top, right, bottom); - Puts(Format("Editor window is located at %d, %d, %d, %d", (int)left, (int)top, (int)right, (int)bottom)); - Puts("Editor window id is " + FormatLong(windowId)); - - long x, y; - Mouse_GetPos(x, y); - Puts(Format("Mouse pos is %d, %d", (int)x, (int)y)); - Mouse_SetPos(200, 200, windowId); - -#if defined(PLATFORM_WIN32) - Mouse_LeftClick(); - Keyb_SendKeys("{HOME}This text is added by Keyb_SendKeys.\n"); - - Keyb_SendKeys("And the window resized and moved by Window_SetRect.\n", 0, 0); - Keyb_SendKeys("And a window capture in c:\\Windowgrab.bmp.\n", 0, 0); - Keyb_SendKeys("Some chars just for test: \\/:;,.ºª^[]{}´?¿~#@!¡\n", 0, 0); - Window_SetRect(windowId, 10, 10, 800, 400); -#endif - Window_SaveCapture(windowId, AppendFileName(GetDesktopFolder(), "Windowgrab")); - } - } - Puts("\nPress enter to terminate 'test.txt'"); TestGetchar(); - - int processId; - TimeStop t; - while(-1 == (processId = GetProcessIdFromWindowCaption("test.txt", false))) { - if (t.Elapsed() > 10000) - break; - } - if (processId == -1) - Puts("Window was closed before!"); - else { - Puts("Ending process in max 2 seconds"); - if (!ProcessTerminate(processId, 2000)) - Puts("Impossible to end process"); - else - Puts("Process terminated"); - } - Puts("\nPress enter to continue..."); TestGetchar(); - - Puts("\nWindows list:"); - Array widL, pidL; - Array name, fileName, caption; - GetWindowsList(widL, pidL, name, fileName, caption); - for (int i = 0; i < widL.GetCount(); ++i) { - Puts(Format("Window hwnd: %6.f, processId: %6.f, Name: %s", (double)widL[i], (double)pidL[i], name[i])); - Puts(Format(" File name: %s", fileName[i])); - Puts(Format(" Window caption: '%s'", caption[i])); - if ((i/20) > (i-1)/20) { - Puts("\nPress enter to continue with the next 20 windows..."); TestGetchar(); - } - } - Puts("\nPress enter to continue..."); TestGetchar(); - - Puts("\nProcess list:"); - pidL.Clear(); - Array pNames; - if (!GetProcessList(pidL, pNames)) - Puts("Error getting process info"); - else { - for (int i = 0; i < pidL.GetCount(); ++i) { - int priority = GetProcessPriority(pidL[i]); - Puts(Format("Id %6.f: Priority: %s, Program: %s", (double)pidL[i], priority >= 0? AsString(priority): "Not accesible", pNames[i])); - } - } - Puts("\nPress enter to end..."); TestGetchar(); -} - -CONSOLE_APP_MAIN -{ - FileDelete(AppendFileName(GetDesktopFolder(), "log")); - Puts("Introduce enter or (l) to log off, (r) to reboot or (s) to shutdown"); - char str[50]; - fgets(str, 49, stdin); - if (*str == 'l') - Shutdown("logoff"); - else if (*str == 'r') - Shutdown("reboot"); - else if (*str == 's') - Shutdown("shutdown"); - - Puts("Introduce number of test cycles or just type enter to run it once: "); - fgets(str, 49, stdin); - int numTests = atoi(str); - for (int i = 0; i < numTests; ++i) - Test(); - end = true; - Test(); -}