mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
attempt to fix DateTime.Now issue
This commit is contained in:
parent
92827b419f
commit
d2c1446225
@ -250,7 +250,6 @@ namespace ClassicalSharp {
|
||||
"_Gold_Iron_Double slab_Slab_Brick_TNT_Bookshelf_Mossy rocks_Obsidian_Cobblestone slab_Rope_Sandstone" +
|
||||
"_Snow_Fire_Light pink_Forest green_Brown_Deep blue_Turquoise_Ice_Ceramic tile_Magma_Pillar_Crate_Stone brick";
|
||||
|
||||
static StringBuffer buffer = new StringBuffer(64);
|
||||
static string DefaultName(BlockID block) {
|
||||
if (block >= Block.CpeCount) return "Invalid";
|
||||
|
||||
@ -258,14 +257,11 @@ namespace ClassicalSharp {
|
||||
int start = 0;
|
||||
for (int i = 0; i < block; i++)
|
||||
start = RawNames.IndexOf('_', start) + 1;
|
||||
|
||||
int end = RawNames.IndexOf('_', start);
|
||||
if (end == -1) end = RawNames.Length;
|
||||
|
||||
buffer.Clear();
|
||||
for (int i = start; i < end; i++) {
|
||||
buffer.Append(RawNames[i]);
|
||||
}
|
||||
return buffer.ToString();
|
||||
return RawNames.Substring(start, end - start);
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace ClassicalSharp {
|
||||
StreamWriter writer = null;
|
||||
void LogChatToFile(string text) {
|
||||
if (logName == null || !game.ChatLogging) return;
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime now = Utils.LocalNow();
|
||||
|
||||
if (now.Day != last.Day || now.Month != last.Month || now.Year != last.Year) {
|
||||
Dispose();
|
||||
|
@ -379,7 +379,7 @@ namespace ClassicalSharp {
|
||||
Platform.DirectoryCreate("screenshots");
|
||||
}
|
||||
|
||||
string timestamp = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss");
|
||||
string timestamp = Utils.LocalNow().ToString("dd-MM-yyyy-HH-mm-ss");
|
||||
string file = "screenshot_" + timestamp + ".png";
|
||||
string path = PathIO.Combine("screenshots", file);
|
||||
|
||||
|
@ -216,7 +216,7 @@ namespace ClassicalSharp.Network {
|
||||
|
||||
static DateTime GetLastModified(HttpWebResponse response) {
|
||||
// System.NotSupportedException: Can't get timezone name.
|
||||
// gets thrown on some platforms with DateTime.Now
|
||||
// Gets thrown on some platforms with DateTime.Now
|
||||
try {
|
||||
if (response.Headers.Get("Last-Modified") != null)
|
||||
return response.LastModified;
|
||||
|
@ -47,7 +47,7 @@ namespace ClassicalSharp {
|
||||
using (StreamWriter w = new StreamWriter(fs))
|
||||
{
|
||||
w.WriteLine("=== crash occurred ===");
|
||||
w.WriteLine("Time: " + DateTime.Now);
|
||||
w.WriteLine("Time: " + Utils.LocalNow());
|
||||
|
||||
string platform = Configuration.RunningOnMono ? "Mono " : ".NET ";
|
||||
platform += Environment.Version;
|
||||
|
@ -2,6 +2,8 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
#if !LAUNCHER
|
||||
using ClassicalSharp.Model;
|
||||
#endif
|
||||
@ -29,6 +31,32 @@ namespace ClassicalSharp {
|
||||
|
||||
public const int StringLength = 64;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack=2)]
|
||||
internal struct SYSTEMTIME {
|
||||
public ushort Year, Month, DayOfWeek, Day;
|
||||
public ushort Hour, Minute, Second, Millis;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void GetLocalTime(out SYSTEMTIME st);
|
||||
|
||||
static DateTime LocalNow_Windows() {
|
||||
SYSTEMTIME st; GetLocalTime(out st);
|
||||
return new DateTime(st.Year, st.Month, st.Day, st.Hour, st.Minute,
|
||||
st.Second, st.Millis, DateTimeKind.Local);
|
||||
}
|
||||
|
||||
public static DateTime LocalNow() {
|
||||
// System.NotSupportedException: Can't get timezone name.
|
||||
// Gets thrown on some platforms with DateTime.Now
|
||||
try {
|
||||
// avoid pinvoke-ing GetLocalTime function on non-windows OS
|
||||
if (OpenTK.Configuration.RunningOnWindows) return LocalNow_Windows();
|
||||
} catch { }
|
||||
return DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
public static string StripColours(string value) {
|
||||
if (value.IndexOf('&') == -1) return value;
|
||||
char[] output = new char[value.Length];
|
||||
|
@ -18,7 +18,7 @@ namespace Launcher.Patcher {
|
||||
public ZipWriter(Stream stream) {
|
||||
this.stream = stream;
|
||||
writer = new BinaryWriter(stream);
|
||||
now = DateTime.Now;
|
||||
now = Utils.LocalNow();
|
||||
}
|
||||
|
||||
internal ZipEntry[] entries;
|
||||
|
Loading…
x
Reference in New Issue
Block a user