This repository was archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
83 lines (77 loc) · 2.75 KB
/
Copy pathUtil.cs
File metadata and controls
83 lines (77 loc) · 2.75 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
namespace Ultimate_Steam_Acount_Manager
{
class Util
{
private static string CachedDataFolder = null;
public static string GetDataFolder()
{
if(string.IsNullOrEmpty(CachedDataFolder))
CachedDataFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
+ Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar;
return CachedDataFolder;
}
public static SteamAccount GetAccountByName(List<SteamAccount> accounts, string name)
{
if (accounts == null) return null;
foreach (SteamAccount account in accounts)
{
if (account.Login == name) return account;
}
return null;
}
public static string GetRelativeTimeString(long time)
{
if (time == 0) return "never";
var ts = new TimeSpan((SteamAuth.Util.GetSystemUnixTime() - time) * 10000000);
double delta = Math.Abs(ts.TotalSeconds);
if (delta < 60)
{
return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
}
if (delta < 120)
{
return "a minute ago";
}
if (delta < 2700) // 45 * 60
{
return ts.Minutes + " minutes ago";
}
if (delta < 5400) // 90 * 60
{
return "an hour ago";
}
if (delta < 86400) // 24 * 60 * 60
{
return ts.Hours + " hours ago";
}
if (delta < 172800) // 48 * 60 * 60
{
return "yesterday";
}
if (delta < 2592000) // 30 * 24 * 60 * 60
{
return ts.Days + " days ago";
}
if (delta < 31104000) // 12 * 30 * 24 * 60 * 60
{
int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
return months <= 1 ? "one month ago" : months + " months ago";
}
int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
return years <= 1 ? "one year ago" : years + " years ago";
}
public static TDelegate GetVirtualFunction<TDelegate>(IntPtr obj, int index)
{
IntPtr vTable = Marshal.ReadIntPtr(obj, 0);
IntPtr function = Marshal.ReadIntPtr(vTable, index * Marshal.SizeOf<IntPtr>());
return Marshal.GetDelegateForFunctionPointer<TDelegate>(function);
}
}
}