This repository was archived by the owner on Feb 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (103 loc) · 4.22 KB
/
Copy pathProgram.cs
File metadata and controls
116 lines (103 loc) · 4.22 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
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace PowerCacheOffice
{
internal static class Program
{
public static readonly string AppName = "Power Cache Office";
private static readonly string powerCacheOfficeLogFolder = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"PowerCacheOffice\log");
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.SetHighDpiMode(HighDpiMode.PerMonitor);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += (s, e) => ErrorHandling(e.Exception);
AppDomain.CurrentDomain.UnhandledException += (s, e) => ErrorHandling((Exception)e.ExceptionObject);
try
{
App winAppBase = new App();
winAppBase.Run(args);
}
catch (Exception ex) { ErrorHandling(ex); }
}
static void ErrorHandling(Exception exception)
{
try
{
if (!Directory.Exists(powerCacheOfficeLogFolder)) Directory.CreateDirectory(powerCacheOfficeLogFolder);
File.WriteAllText(
Path.Combine(powerCacheOfficeLogFolder, DateTime.Now.ToString("yyyyMMdd") + "-" + Guid.NewGuid().ToString("N") + ".log"), exception.ToString());
MessageBox.Show(exception.Message, AppName);
}
finally { Environment.Exit(1); }
}
public static void CopyFileAndAttributes(string sourcePath, string destinationPath)
{
File.Copy(sourcePath, destinationPath, true);
var attributes = File.GetAttributes(sourcePath);
File.SetAttributes(destinationPath, attributes);
var creationTime = File.GetCreationTime(sourcePath);
var lastAccessTime = File.GetLastAccessTime(sourcePath);
var lastWriteTime = File.GetLastWriteTime(sourcePath);
File.SetCreationTime(destinationPath, creationTime);
File.SetLastAccessTime(destinationPath, lastAccessTime);
File.SetLastWriteTime(destinationPath, lastWriteTime);
}
public static void SortTabIndex(Form form)
{
var children = new List<Control>();
foreach (Control child in form.Controls) children.Add(child);
children.Sort((x, y) =>
{
if (x.Top == y.Top) return x.Left.CompareTo(y.Left);
return x.Top.CompareTo(y.Top);
});
for (int i = 0; i < children.Count; i++) children[i].TabIndex = i;
}
public static void ChangeDarkMode(Form form, bool enabled)
{
NativeMethods.DwmSetWindowAttribute(
form.Handle, NativeMethods.DWMWA_USE_IMMERSIVE_DARK_MODE, ref enabled, (uint)Marshal.SizeOf(typeof(bool)));
if (enabled)
{
form.BackColor = Color.FromArgb(33, 33, 33);
form.ForeColor = Color.FromArgb(255, 255, 255);
}
else
{
form.BackColor = Color.FromArgb(243, 243, 243);
form.ForeColor = Color.FromArgb(0, 0, 0);
}
ChangeColor(form);
void ChangeColor(Control ctrl)
{
foreach (Control c in ctrl.Controls)
{
try
{
if (enabled)
{
c.BackColor = Color.FromArgb(33, 33, 33);
c.ForeColor = Color.FromArgb(255, 255, 255);
}
else
{
c.BackColor = Color.FromArgb(243, 243, 243);
c.ForeColor = Color.FromArgb(0, 0, 0);
}
}
catch { }
ChangeColor(c);
}
}
}
}
}