Skip to content

Commit d82ddd0

Browse files
New local folder and autofocus to active font.
- Changed Font Manager folder to appdata, will fix problems with "DirectoryNotFoundException" - Added active font is focused at default - Added autofocus to already runnin font manager instances - Renamed Assembly to "Font Manager.exe"
1 parent 31a600d commit d82ddd0

16 files changed

+100
-86
lines changed

CSGO Font Manager/CSGO Font Manager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>WinExe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>CSGO_Font_Manager</RootNamespace>
11-
<AssemblyName>CSGO Font Manager</AssemblyName>
11+
<AssemblyName>Font Manager</AssemblyName>
1212
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

CSGO Font Manager/Form1.cs

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.Drawing;
56
using System.Drawing.Text;
@@ -18,13 +19,15 @@ namespace CSGO_Font_Manager
1819
{
1920
public partial class Form1 : Form
2021
{
21-
public const string AssemblyVersion = "3.2.0.0";
22-
public static string VersionNumber = "3.2"; // Remember to update stableVersion.txt when releasing a new stable update.
22+
public const string AssemblyVersion = "3.3.0.0";
23+
public static string VersionNumber = "3.3"; // Remember to update stableVersion.txt when releasing a new stable update.
2324
// This will notify all Font Manager 2.0 clients that there is an update available.
2425
// To push the notification, commit and push to the master repository on GitHub.
2526
private readonly string CurrentVersion = "https://raw.githubusercontent.com/WilliamRagstad/Font-Manager/master/CSGO%20Font%20Manager/stableVersion.txt";
26-
27-
public static string HomeFolder = $@"C:\Users\{Environment.UserName}\Documents\";
27+
28+
public static string OldFontManagerFolder = $@"C:\Users\{Environment.UserName}\Documents\Font Manager\";
29+
public static string HomeFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";
30+
2831
public static string FontManagerFolder = HomeFolder + @"Font Manager\";
2932
public static string FontsFolder = FontManagerFolder + @"Fonts\";
3033
public static string DataPath = FontManagerFolder + @"Data\";
@@ -59,7 +62,7 @@ private void Form1_Load(object sender, EventArgs e)
5962
version_label.Text = "Version " + VersionNumber;
6063

6164
SetupFolderStructure();
62-
65+
6366
SettingsManager = new JsonManager<Settings>(SettingsFile);
6467
Settings = SettingsManager.Load();
6568

@@ -71,8 +74,18 @@ private void Form1_Load(object sender, EventArgs e)
7174
switchView(FormViews.Main);
7275
}
7376

77+
[DllImport("user32.dll")]
78+
public static extern int SetForegroundWindow(IntPtr hwnd);
79+
7480
private void AutoFocusRunningInstance()
7581
{
82+
string title = Process.GetCurrentProcess().ProcessName;
83+
Process[] runningFM = Process.GetProcessesByName(title);
84+
if (runningFM.Length > 1)
85+
{
86+
SetForegroundWindow(runningFM[0].MainWindowHandle);
87+
Environment.Exit(0);
88+
}
7689
// Not implemented
7790
}
7891

@@ -91,7 +104,7 @@ private void checkForUpdates()
91104
using(var reader = new StreamReader(content)){
92105
newVersion = reader.ReadToEnd().Replace("\n","");
93106

94-
107+
if (newVersion == Settings.HideNewVersions) return;
95108
}
96109
}
97110
catch (Exception e)
@@ -121,54 +134,48 @@ private void checkForUpdates()
121134
"Do you want to continue getting update notifications?",
122135
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
123136
{
124-
Settings.hideNewVersions = VersionNumber;
137+
Settings.HideNewVersions = VersionNumber;
125138
}
126139
}
127140
}
128141

129142
private static void SetupFolderStructure()
130143
{
131-
new FileIOPermission(FileIOPermissionAccess.Write, HomeFolder).Demand();
132-
new FileIOPermission(FileIOPermissionAccess.Write, FontManagerFolder).Demand();
133-
new FileIOPermission(FileIOPermissionAccess.Write, FontsFolder).Demand();
134-
new FileIOPermission(FileIOPermissionAccess.Write, DataPath).Demand();
135-
136-
ObtainFolderPermission(HomeFolder);
137-
ObtainFolderPermission(FontManagerFolder);
138-
139-
try
144+
if (Directory.Exists(HomeFolder))
140145
{
141-
Directory.CreateDirectory(HomeFolder);
142146
Directory.CreateDirectory(FontManagerFolder);
143147
Directory.CreateDirectory(FontsFolder);
144148
Directory.CreateDirectory(DataPath);
145149
}
146-
catch
150+
else
147151
{
148-
System.Windows.Forms.DialogResult dr = MessageBox.Show("Font Manager does not seem to have permission to the document directory!", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
149-
if (dr == DialogResult.Retry) SetupFolderStructure();
152+
MessageBox.Show("Appdata does not exist... You're not running this on linux or mac huh..", "No can do");
153+
Application.Exit(new CancelEventArgs());
150154
}
151-
}
152-
153-
public static void ObtainFolderPermission(string folderPath)
154-
{
155-
var directoryInfo = new DirectoryInfo(folderPath);
156-
var directorySecurity = directoryInfo.GetAccessControl();
157-
var currentUserIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
158-
159-
foreach (IdentityReference group in currentUserIdentity.Groups)
155+
156+
// Transfer all files from old (if existing) FontManager folder to the new one in AppData
157+
if (Directory.Exists(OldFontManagerFolder))
160158
{
161-
var fileSystemRule = new System.Security.AccessControl.FileSystemAccessRule(group,
162-
System.Security.AccessControl.FileSystemRights.Read,
163-
System.Security.AccessControl.InheritanceFlags.ObjectInherit |
164-
System.Security.AccessControl.InheritanceFlags.ContainerInherit,
165-
System.Security.AccessControl.PropagationFlags.None,
166-
System.Security.AccessControl.AccessControlType.Allow);
167-
168-
directorySecurity.AddAccessRule(fileSystemRule);
159+
if (Directory.Exists(OldFontManagerFolder + @"Fonts\"))
160+
foreach (string fontFolder in Directory.GetFileSystemEntries(OldFontManagerFolder + @"Fonts\"))
161+
{
162+
string dir = FontsFolder + Path.GetFileName(fontFolder) + @"\";
163+
if (Directory.Exists(dir)) continue;
164+
Directory.CreateDirectory(dir);
165+
foreach (string file in Directory.GetFiles(fontFolder))
166+
{
167+
string dst = dir + Path.GetFileName(file);
168+
if (!File.Exists(dst))
169+
File.Copy(file, dst);
170+
}
171+
}
172+
173+
if (File.Exists(OldFontManagerFolder + @"Data\settings.json") && !File.Exists(SettingsFile))
174+
File.Copy(OldFontManagerFolder + @"Data\settings.json", SettingsFile);
175+
176+
if (Directory.Exists(OldFontManagerFolder))
177+
Directory.Delete(OldFontManagerFolder, true);
169178
}
170-
171-
directoryInfo.SetAccessControl(directorySecurity);
172179
}
173180

174181
private void listBox1_Click(object sender, EventArgs e)
@@ -240,10 +247,10 @@ private void showFontPreview()
240247

241248
private void addFont_button_Click(object sender, EventArgs e)
242249
{
243-
if (Settings.proTips)
250+
if (Settings.ProTips)
244251
{
245252
MessageBox.Show("Protip: If you want you can also just drag-and-drop fonts inside the font list.", "Drag and Drop!", MessageBoxButtons.OK, MessageBoxIcon.Information);
246-
Settings.proTips = false;
253+
Settings.ProTips = false;
247254
}
248255

249256
switchView(FormViews.AddSystemFont);
@@ -378,7 +385,7 @@ private void button2_Click(object sender, EventArgs e)
378385

379386
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
380387
{
381-
Process.Start("https://github.com/WilliamRagstad/Font-Manager");
388+
Process.Start("https://github.com/WilliamRagstad/Font-Manager/blob/master/README.md#introduction");
382389
}
383390

384391
private void donate_button_Click(object sender, EventArgs e)
@@ -392,15 +399,20 @@ private void donate_button_Click(object sender, EventArgs e)
392399

393400
private void refreshFontList()
394401
{
402+
int activeFontIndex = 0;
395403
//refresh list of fonts
396404
string[] dirs = Directory.GetDirectories(FontsFolder);
397405
listBox1.Items.Clear();
406+
int index = 0;
398407
foreach (string dir in dirs)
399408
{
409+
index++;
410+
400411
string foldername = Path.GetFileName(dir);
401412
if (File.Exists(dir + "\\fonts.conf"))
402413
{
403414
listBox1.Items.Add(foldername);
415+
if (Settings.ActiveFont != null && Settings.ActiveFont.Equals(foldername)) activeFontIndex = index;
404416

405417
// Add the font to the private font collection
406418
foreach (string file in Directory.GetFiles(dir))
@@ -424,7 +436,7 @@ private void refreshFontList()
424436

425437
// Add default font
426438
listBox1.Items.Insert(0, defaultFontName);
427-
listBox1.SelectedIndex = 0;
439+
listBox1.SelectedIndex = activeFontIndex;
428440
}
429441

430442
private List<string> GetFiles(string path, string pattern)
@@ -456,7 +468,7 @@ private void apply_button_Click(object sender, EventArgs e)
456468
{
457469

458470
//Get the csgo path (home folder...) if data file not found...
459-
if (Settings.csgoPath != null)
471+
if (Settings.CsgoPath != null)
460472
{
461473
// Make sure the folders exists
462474
string csgoConfD = csgoFontsFolder + "\\conf.d";
@@ -517,6 +529,8 @@ private void apply_button_Click(object sender, EventArgs e)
517529
MessageBox.Show($"Successfully applied {listBox1.SelectedItem}!" +
518530
(csgoIsRunning ? "\n\nRestart CS:GO for the font to take effect." : ""),
519531
"Font Applied!", MessageBoxButtons.OK, MessageBoxIcon.Information);
532+
533+
Settings.ActiveFont = listBox1.SelectedItem.ToString();
520534
}
521535
else
522536
{
@@ -604,7 +618,7 @@ private void apply_button_Click(object sender, EventArgs e)
604618
public static void LoadCSGOFolder(bool manual = false)
605619
{
606620

607-
if (Settings.csgoPath != null) csgoFontsFolder = Settings.csgoPath + @"\csgo\panorama\fonts";
621+
if (Settings.CsgoPath != null) csgoFontsFolder = Settings.CsgoPath + @"\csgo\panorama\fonts";
608622
else
609623
{
610624
string csgoPath = tryLocatingCSGOFolder();
@@ -623,7 +637,7 @@ public static void LoadCSGOFolder(bool manual = false)
623637
"Path Found!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
624638
{
625639
SetupFolderStructure(); // Make sure all folders exists...
626-
Settings.csgoPath = csgoPath;
640+
Settings.CsgoPath = csgoPath;
627641
LoadCSGOFolder(); // Update the csgo fonts folder path
628642
}
629643
else
@@ -756,7 +770,7 @@ public static void AddFont(byte[] fontBytes)
756770
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
757771
{
758772
if (MessageBox.Show("This will only restore the path to Counter Strike: Global Offensive and restore utility programs (in case they need to be updated). If you want to delete all fonts, you must do so through the program.\n\n" +
759-
"Current CS:GO Folder: " + Settings.csgoPath + "\n\nAre you sure you want to reset Font Manager?", "Reset?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
773+
"Current CS:GO Folder: " + Settings.CsgoPath + "\n\nAre you sure you want to reset Font Manager?", "Reset?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
760774
{
761775
Directory.Delete(DataPath, true);
762776
LoadCSGOFolder();
@@ -854,7 +868,8 @@ void insertAt(int index)
854868
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
855869
{
856870
// Save settings
857-
SettingsManager.Save(Settings);
871+
if (Settings != null)
872+
SettingsManager.Save(Settings);
858873
}
859874
}
860875
}

CSGO Font Manager/JsonManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public T Load()
2121
public void Save(T Data)
2222
{
2323
string json = JsonConvert.SerializeObject(Data, Formatting.Indented);
24+
(new FileInfo(_targetFile)).Directory.Create();
2425
File.WriteAllText(_targetFile, json);
2526
}
2627
}

CSGO Font Manager/Settings.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ namespace CSGO_Font_Manager
88
{
99
public class Settings
1010
{
11-
public string csgoPath { get; set; }
12-
public bool proTips { get; set; } = true;
13-
public string hideNewVersions { get; set; }
11+
public string CsgoPath { get; set; }
12+
public bool ProTips { get; set; } = true;
13+
public string HideNewVersions { get; set; }
14+
public string ActiveFont { get; set; }
1415
}
1516
}
-4.66 MB
Binary file not shown.
-71.5 KB
Binary file not shown.

CSGO Font Manager/obj/Debug/CSGO Font Manager.csproj.FileListAbsolute.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects
1010
C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects\Font-Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.CoreCompileInputs.cache
1111
C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects\Font-Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.exe
1212
C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects\Font-Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.pdb
13-
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\CSGO Font Manager.exe.config
14-
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\CSGO Font Manager.exe
15-
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\CSGO Font Manager.pdb
1613
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\ActiproSoftware.Shared.WinForms.dll
1714
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\ActiproSoftware.SyntaxEditor.WinForms.dll
1815
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Newtonsoft.Json.dll
@@ -24,5 +21,9 @@ D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\C
2421
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.GenerateResource.cache
2522
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.CoreCompileInputs.cache
2623
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.CopyComplete
27-
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.exe
28-
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.pdb
24+
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csprojAssemblyReference.cache
25+
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Font Manager.exe.config
26+
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Font Manager.exe
27+
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Font Manager.pdb
28+
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\Font Manager.exe
29+
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\Font Manager.pdb
Binary file not shown.
-4.66 MB
Binary file not shown.
-71.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)