This repository has been archived by the owner on Feb 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cls_Global_Func.cs
95 lines (82 loc) · 2.33 KB
/
cls_Global_Func.cs
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
using System;
using System.IO;
using System.Media;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using Microsoft.Win32;
namespace hyperdesktop2
{
public static class Global_Func
{
public static ImageFormat ext_to_imageformat(String ext)
{
switch(ext.ToLower()) {
case "jpeg":
case "jpg":
return ImageFormat.Jpeg;
case "png":
return ImageFormat.Png;
default:
return ImageFormat.Bmp;
}
}
public static Boolean str_to_bool(String str)
{
return str.ToLower() == "true";
}
public static String get_text_inbetween(String input, String a, String b)
{
return input.Substring(input.IndexOf(a) + a.Length, input.IndexOf(b) - input.IndexOf(a) - a.Length);
}
public static String bmp_to_base64(Bitmap bmp, ImageFormat format)
{
using (var stream = new MemoryStream())
{
bmp.Save(stream, format);
Byte[] bytes = stream.ToArray();
return Convert.ToBase64String(bytes);
}
}
readonly public static RegistryKey reg_key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
public static void run_at_startup(Boolean run)
{
app_data_folder_create();
if(run)
reg_key.SetValue("Hyperdesktop2", Settings.exe_path);
else
reg_key.DeleteValue("Hyperdesktop2", false);
}
public static void app_data_folder_create() {
if(!Directory.Exists(Settings.app_data))
Directory.CreateDirectory(Settings.app_data);
}
public static void copy_files() {
if(!File.Exists(Settings.exe_path))
File.Copy(
Application.ExecutablePath,
Settings.exe_path
);
try {
if(!Directory.Exists(Settings.app_data + "\\sounds\\")) {
Directory.CreateDirectory(Settings.app_data + "\\sounds\\");
foreach(var file in Directory.GetFiles(Environment.CurrentDirectory + "\\sounds"))
File.Copy(file, Settings.app_data + "\\sounds\\" + Path.GetFileName(file));
}
} catch (Exception ex) {
Console.WriteLine("Couldn't copy sound files.");
Console.WriteLine(ex.Message);
}
}
public static void play_sound(String file)
{
try {
if(Settings.sound_effects)
using (var sound_player = new SoundPlayer("sounds\\" + file))
sound_player.Play();
} catch {
Console.WriteLine("Can't find audio file: " + file);
}
}
}
}