summary refs log tree commit diff stats
path: root/src/common/common.vcxproj
AgeCommit message (Expand)Author
2014-09-17win32: Fixed build break due to 7a4a024Arnavion
2014-06-04win32: Use config.h instead of config-win32.hTingPing
2014-06-03win32: Don't auto-generate version.txtTingPing
2014-03-18win32: Powershell.exe absolutely needs "-File" when running scripts or else i...Arnavion
2014-02-06Use a single marshal file for entire projectTingPing
2013-12-27Replaced use of T4 templates with PS-based templates.Arnavion
2013-11-03Use correct path to TextTransform.exe depending on the platform.Arnavion
2013-10-12win32: Use version information from configure.ac to populate the Windows-spec...Arnavion
2013-09-26Remove remnants of native file dialogsTingPing
2013-09-15Convert project files to vs2013Eustachy Kapusta
2013-07-24Move optimization settings from all subsequent projects to hexchat.propsEustachy Kapusta
2013-04-25win32: Moved PlatformToolset configuration to individual project files. It sh...Arnavion
2013-04-14Remove one warning bypassBerke Viktor
2013-04-03Remove strlutilBerke Viktor
2012-11-11Fix 4996 warningsBerke Viktor
2012-11-11Hide 4996 warnings in all projects and fix license copyBerke Viktor
2012-11-10Eliminate some more warnings and hide less warnings in VSBerke Viktor
2012-11-06Disable some stupid warnings without the WDKBerke Viktor
2012-11-04Ignore specific warnings for common and fe-gtk, all should be eliminated at s...Berke Viktor
2012-10-28Use Consolas as the default font where availableBerke Viktor
2012-10-27Ignore generated config.h properly on UnixBerke Viktor
2012-10-24A lot more rebrandingBerke Viktor
2012-10-21Move warning level to property sheetBerke Viktor
2012-10-21Relocate typedef.hBerke Viktor
2012-10-03Complete the VS2010 reversionBerke Viktor
2012-10-03Revert to VS2010 part4Berke Viktor
2012-10-02Oops, wrong find'n'replaceBerke Viktor
2012-10-02Remove hardcoding as much as possibleBerke Viktor
2012-10-02Change platform toolset to Visual Studio 2012Berke Viktor
2012-09-24Add strlcat() and strlcpy(), might convert to them in the futureBerke Viktor
2012-09-15Update solution to Visual Studio 2012 Express and get rid of mpcInfoBerke Viktor
2012-07-21Add _AMD64_ definition for x64 builds, make Visual Studio even happierBerke Viktor
2012-07-21Add trailing backslashes to Output and Intermediate directories, make Visual ...Berke Viktor
2012-07-11Rebranding on the file levelBerke Viktor
2012-06-15Add x64 support to the VS solutionBerke Viktor
2012-06-15LOTS of fixes to the VS solutionBerke Viktor
2012-06-10Migrate VS solution to VS2010+WDK7Berke Viktor
0000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * SysInfo - sysinfo plugin for HexChat
 * Copyright (c) 2015 Patrick Griffis.
 *
 * This program is free software you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

 /*
	* Some snippets based upon Textual's System Profiler plugin.
	* https://github.com/Codeux-Software/Textual
	*/

#import <Cocoa/Cocoa.h>

#include <sys/sysctl.h>
#include <mach/mach.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
#include <mach/mach_vm.h>

#include <glib.h>

#include "format.h"
#include "df.h"

static char *
get_os (void)
{
	NSDictionary *systemversion = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
	NSString *build = [systemversion objectForKey:@"ProductBuildVersion"];
	if (!build)
		return NULL;
	NSString *version = [systemversion objectForKey:@"ProductUserVisibleVersion"];
	if (!version)
	{
		[build release];
		return NULL;
	}

	NSDictionary *profiler = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/com.apple.SystemProfiler.plist" stringByExpandingTildeInPath]];
	NSDictionary *names = [profiler objectForKey:@"OS Names"];
	NSString *os_name = nil;

	for (NSString *name in names)
	{
		if ([name hasPrefix:build])
		{
			os_name = [names objectForKey:name];
			break;
		}
	}
	[build release];

	if (!os_name)
	{
		[version release];
		return NULL;
	}

	char *ret = g_strdup_printf ("%s %s", [os_name UTF8String], [version UTF8String]);
	[version release];

	return ret;
}

static char *
get_os_fallback (void)
{
#if !defined (MAC_OS_X_VERSION_10_9) || MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9
	SInt32 ver_major = 0,
	       ver_minor = 0,
	       ver_patch = 0;

	Gestalt (gestaltSystemVersionMajor, &ver_major);
	Gestalt (gestaltSystemVersionMinor, &ver_minor);
	Gestalt (gestaltSystemVersionBugFix, &ver_patch);

	return g_strdup_printf ("OS X %d.%d.%d", ver_major, ver_minor, ver_patch);
#else
	NSProcessInfo *info = [NSProcessInfo processInfo];
	NSOperatingSystemVersion version = [info operatingSystemVersion];

	return g_strdup_printf ("OS X %ld.%ld.%ld", version.majorVersion, version.minorVersion, version.patchVersion);
#endif
}
char *
sysinfo_backend_get_os(void)
{
	static char *os_str = NULL;
	if (!os_str)
	{
		os_str = get_os();
		if (!os_str)
			os_str = get_os_fallback();
	}
	return g_strdup (os_str);
}

char *
sysinfo_backend_get_disk(void)
{
	gint64 total, free_space;

	if (xs_parse_df (&total, &free_space))
	{
		return NULL;
	}

	return sysinfo_format_disk (total, free_space);
}

static guint64
get_free_memory (void)
{
	mach_msg_type_number_t infoCount = (sizeof(vm_statistics_data_t) / sizeof(natural_t));

	vm_size_t pagesize;
	vm_statistics_data_t vm_stat;

	host_page_size(mach_host_self(), &pagesize);

	if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat, &infoCount) == KERN_SUCCESS)
		return ((vm_stat.inactive_count + vm_stat.free_count) * pagesize);

	return 0;
}

char *
sysinfo_backend_get_memory(void)
{
	NSProcessInfo *info = [NSProcessInfo processInfo];
	guint64 totalmem, freemem;

	totalmem = [info physicalMemory];

	if ((freemem = get_free_memory()) == 0)
		return NULL;

	return sysinfo_format_memory (totalmem, freemem);
}

char *
sysinfo_backend_get_cpu(void)
{
	guint64 cpu_clock_uint = 0;
	double cpu_clock;
	char cpu_string[256];
	gsize len;
	gboolean giga = FALSE;

	len = sizeof(cpu_string);
	if (sysctlbyname ("machdep.cpu.brand_string", cpu_string, &len, NULL, 0) != 0)
		return NULL;
	cpu_string[sizeof(cpu_string) - 1] = '\0';

	len = sizeof(cpu_clock_uint);
	if (sysctlbyname("hw.cpufrequency", &cpu_clock_uint, &len, NULL, 0) < 0)
		return NULL;

	cpu_clock = cpu_clock_uint / 1000000;
	if (cpu_clock > 1000)
	{
		cpu_clock /= 1000;
		giga = TRUE;
	}

	if (giga)
		return g_strdup_printf ("%s (%.2fGHz)", cpu_string, cpu_clock);
	else
		return g_strdup_printf ("%s (%.0fMHz)", cpu_string, cpu_clock);
}

static char *
get_gpu(void)
{
	CFMutableDictionaryRef pciDevices = IOServiceMatching("IOPCIDevice");
	io_iterator_t entry_iterator, serviceObject;

	if (IOServiceGetMatchingServices(kIOMasterPortDefault, pciDevices, &entry_iterator) != kIOReturnSuccess)
		return NULL;

	GString *gpu_list = g_string_new(NULL);
	while ((serviceObject = IOIteratorNext(entry_iterator)))
	{
		CFMutableDictionaryRef serviceDictionary;

		kern_return_t status = IORegistryEntryCreateCFProperties(serviceObject, &serviceDictionary,
														 kCFAllocatorDefault, kNilOptions);

		if (status != kIOReturnSuccess)
		{
			IOObjectRelease(serviceObject);
			continue;
		}

		const void *class = CFDictionaryGetValue(serviceDictionary, @"class-code");
		if (!class || *(guint32*)CFDataGetBytePtr(class) != 0x30000) /* DISPLAY_VGA */
		{
			CFRelease(serviceDictionary);
			continue;
		}

		const void *model = CFDictionaryGetValue(serviceDictionary, @"model");
		if (model)
		{
			if (CFGetTypeID(model) == CFDataGetTypeID() && CFDataGetLength(model) > 1)
			{
				if (gpu_list->len != 0)
						g_string_append (gpu_list, ", ");
				g_string_append_len (gpu_list, (const char*)CFDataGetBytePtr(model), CFDataGetLength(model) - 1);
			}
		}

		CFRelease(serviceDictionary);
	}

	if (gpu_list->len == 0)
	{
		g_string_free (gpu_list, TRUE);
		return NULL;
	}

	/* The string may contain nul-chars we must replace */
	int i;
	for (i = 0; i < gpu_list->len; i++)
	{
		if (gpu_list->str[i] == '\0')
			gpu_list->str[i] = ' ';
	}

	return g_string_free (gpu_list, FALSE);
}

char *
sysinfo_backend_get_gpu(void)
{
	static char *gpu_str = NULL;
	if (!gpu_str)
		gpu_str = get_gpu();

	return g_strdup (gpu_str);
}

char *
sysinfo_backend_get_sound(void)
{
	return NULL;
}

char *
sysinfo_backend_get_uptime(void)
{
	NSProcessInfo *info = [NSProcessInfo processInfo];
	double uptime = [info systemUptime];

	return sysinfo_format_uptime ((gint64)uptime);
}

char *
sysinfo_backend_get_network(void)
{
	return NULL;
}