Files
@ dd838492cfb4
Branch filter:
Location: seniordesign-ui/GMap.NET.Core/GMap.NET.Internals/Stuff.cs
dd838492cfb4
4.0 KiB
text/x-csharp
some fixes to address some errors with unknown source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
namespace GMap.NET.Internals
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
/// <summary>
/// etc functions...
/// </summary>
internal class Stuff
{
public static string EnumToString(Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);
return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
}
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursorPos")]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool SetCursorPos(int X, int Y);
public static readonly Random random = new System.Random();
public static void Shuffle<T>(List<T> deck)
{
int N = deck.Count;
for(int i = 0; i < N; ++i)
{
int r = i + (int)(random.Next(N - i));
T t = deck[r];
deck[r] = deck[i];
deck[i] = t;
}
}
public static MemoryStream CopyStream(Stream inputStream, bool SeekOriginBegin)
{
const int readSize = 32 * 1024;
byte[] buffer = new byte[readSize];
MemoryStream ms = new MemoryStream();
{
int count = 0;
while((count = inputStream.Read(buffer, 0, readSize)) > 0)
{
ms.Write(buffer, 0, count);
}
}
buffer = null;
if(SeekOriginBegin)
{
inputStream.Seek(0, SeekOrigin.Begin);
}
ms.Seek(0, SeekOrigin.Begin);
return ms;
}
public static bool IsRunningOnVistaOrLater()
{
OperatingSystem os = Environment.OSVersion;
if(os.Platform == PlatformID.Win32NT)
{
Version vs = os.Version;
if(vs.Major >= 6 && vs.Minor >= 0)
{
return true;
}
}
return false;
}
public static bool IsRunningOnWin7orLater()
{
OperatingSystem os = Environment.OSVersion;
if(os.Platform == PlatformID.Win32NT)
{
Version vs = os.Version;
if(vs.Major >= 6 && vs.Minor > 0)
{
return true;
}
}
return false;
}
public static void RemoveInvalidPathSymbols(ref string url)
{
#if !PocketPC
char[] ilg = Path.GetInvalidFileNameChars();
#else
char[] ilg = new char[41];
for(int i = 0; i < 32; i++)
ilg[i] = (char) i;
ilg[32] = '"';
ilg[33] = '<';
ilg[34] = '>';
ilg[35] = '|';
ilg[36] = '?';
ilg[37] = ':';
ilg[38] = '/';
ilg[39] = '\\';
ilg[39] = '*';
#endif
foreach(char c in ilg)
{
url = url.Replace(c, '_');
}
}
}
#if PocketPC
static class Monitor
{
static readonly OpenNETCF.Threading.Monitor2 wait = new OpenNETCF.Threading.Monitor2();
public static void Enter(Stack<LoadTask> tileLoadQueue)
{
wait.Enter();
}
public static void Exit(Stack<LoadTask> tileLoadQueue)
{
wait.Exit();
}
public static void Wait(Stack<LoadTask> tileLoadQueue)
{
wait.Wait();
}
public static bool Wait(Stack<LoadTask> tileLoadQueue, int WaitForTileLoadThreadTimeout, bool p)
{
wait.Wait();
return true;
}
internal static void PulseAll(Stack<LoadTask> tileLoadQueue)
{
wait.PulseAll();
}
}
#endif
}
|