Skip to content

Commit

Permalink
Merge pull request #22 from WilliamRagstad/master
Browse files Browse the repository at this point in the history
New local folder and autofocus to active font.
  • Loading branch information
WilliamRagstad authored Feb 18, 2020
2 parents 3a03861 + d82ddd0 commit c2dbcdd
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 86 deletions.
2 changes: 1 addition & 1 deletion CSGO Font Manager/CSGO Font Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CSGO_Font_Manager</RootNamespace>
<AssemblyName>CSGO Font Manager</AssemblyName>
<AssemblyName>Font Manager</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
111 changes: 63 additions & 48 deletions CSGO Font Manager/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Text;
Expand All @@ -18,13 +19,15 @@ namespace CSGO_Font_Manager
{
public partial class Form1 : Form
{
public const string AssemblyVersion = "3.2.0.0";
public static string VersionNumber = "3.2"; // Remember to update stableVersion.txt when releasing a new stable update.
public const string AssemblyVersion = "3.3.0.0";
public static string VersionNumber = "3.3"; // Remember to update stableVersion.txt when releasing a new stable update.
// This will notify all Font Manager 2.0 clients that there is an update available.
// To push the notification, commit and push to the master repository on GitHub.
private readonly string CurrentVersion = "https://raw.githubusercontent.com/WilliamRagstad/Font-Manager/master/CSGO%20Font%20Manager/stableVersion.txt";

public static string HomeFolder = $@"C:\Users\{Environment.UserName}\Documents\";

public static string OldFontManagerFolder = $@"C:\Users\{Environment.UserName}\Documents\Font Manager\";
public static string HomeFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";

public static string FontManagerFolder = HomeFolder + @"Font Manager\";
public static string FontsFolder = FontManagerFolder + @"Fonts\";
public static string DataPath = FontManagerFolder + @"Data\";
Expand Down Expand Up @@ -59,7 +62,7 @@ private void Form1_Load(object sender, EventArgs e)
version_label.Text = "Version " + VersionNumber;

SetupFolderStructure();

SettingsManager = new JsonManager<Settings>(SettingsFile);
Settings = SettingsManager.Load();

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

[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hwnd);

private void AutoFocusRunningInstance()
{
string title = Process.GetCurrentProcess().ProcessName;
Process[] runningFM = Process.GetProcessesByName(title);
if (runningFM.Length > 1)
{
SetForegroundWindow(runningFM[0].MainWindowHandle);
Environment.Exit(0);
}
// Not implemented
}

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


if (newVersion == Settings.HideNewVersions) return;
}
}
catch (Exception e)
Expand Down Expand Up @@ -121,54 +134,48 @@ private void checkForUpdates()
"Do you want to continue getting update notifications?",
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
Settings.hideNewVersions = VersionNumber;
Settings.HideNewVersions = VersionNumber;
}
}
}

private static void SetupFolderStructure()
{
new FileIOPermission(FileIOPermissionAccess.Write, HomeFolder).Demand();
new FileIOPermission(FileIOPermissionAccess.Write, FontManagerFolder).Demand();
new FileIOPermission(FileIOPermissionAccess.Write, FontsFolder).Demand();
new FileIOPermission(FileIOPermissionAccess.Write, DataPath).Demand();

ObtainFolderPermission(HomeFolder);
ObtainFolderPermission(FontManagerFolder);

try
if (Directory.Exists(HomeFolder))
{
Directory.CreateDirectory(HomeFolder);
Directory.CreateDirectory(FontManagerFolder);
Directory.CreateDirectory(FontsFolder);
Directory.CreateDirectory(DataPath);
}
catch
else
{
System.Windows.Forms.DialogResult dr = MessageBox.Show("Font Manager does not seem to have permission to the document directory!", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dr == DialogResult.Retry) SetupFolderStructure();
MessageBox.Show("Appdata does not exist... You're not running this on linux or mac huh..", "No can do");
Application.Exit(new CancelEventArgs());
}
}

public static void ObtainFolderPermission(string folderPath)
{
var directoryInfo = new DirectoryInfo(folderPath);
var directorySecurity = directoryInfo.GetAccessControl();
var currentUserIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();

foreach (IdentityReference group in currentUserIdentity.Groups)

// Transfer all files from old (if existing) FontManager folder to the new one in AppData
if (Directory.Exists(OldFontManagerFolder))
{
var fileSystemRule = new System.Security.AccessControl.FileSystemAccessRule(group,
System.Security.AccessControl.FileSystemRights.Read,
System.Security.AccessControl.InheritanceFlags.ObjectInherit |
System.Security.AccessControl.InheritanceFlags.ContainerInherit,
System.Security.AccessControl.PropagationFlags.None,
System.Security.AccessControl.AccessControlType.Allow);

directorySecurity.AddAccessRule(fileSystemRule);
if (Directory.Exists(OldFontManagerFolder + @"Fonts\"))
foreach (string fontFolder in Directory.GetFileSystemEntries(OldFontManagerFolder + @"Fonts\"))
{
string dir = FontsFolder + Path.GetFileName(fontFolder) + @"\";
if (Directory.Exists(dir)) continue;
Directory.CreateDirectory(dir);
foreach (string file in Directory.GetFiles(fontFolder))
{
string dst = dir + Path.GetFileName(file);
if (!File.Exists(dst))
File.Copy(file, dst);
}
}

if (File.Exists(OldFontManagerFolder + @"Data\settings.json") && !File.Exists(SettingsFile))
File.Copy(OldFontManagerFolder + @"Data\settings.json", SettingsFile);

if (Directory.Exists(OldFontManagerFolder))
Directory.Delete(OldFontManagerFolder, true);
}

directoryInfo.SetAccessControl(directorySecurity);
}

private void listBox1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -240,10 +247,10 @@ private void showFontPreview()

private void addFont_button_Click(object sender, EventArgs e)
{
if (Settings.proTips)
if (Settings.ProTips)
{
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);
Settings.proTips = false;
Settings.ProTips = false;
}

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

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

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

private void refreshFontList()
{
int activeFontIndex = 0;
//refresh list of fonts
string[] dirs = Directory.GetDirectories(FontsFolder);
listBox1.Items.Clear();
int index = 0;
foreach (string dir in dirs)
{
index++;

string foldername = Path.GetFileName(dir);
if (File.Exists(dir + "\\fonts.conf"))
{
listBox1.Items.Add(foldername);
if (Settings.ActiveFont != null && Settings.ActiveFont.Equals(foldername)) activeFontIndex = index;

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

// Add default font
listBox1.Items.Insert(0, defaultFontName);
listBox1.SelectedIndex = 0;
listBox1.SelectedIndex = activeFontIndex;
}

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

//Get the csgo path (home folder...) if data file not found...
if (Settings.csgoPath != null)
if (Settings.CsgoPath != null)
{
// Make sure the folders exists
string csgoConfD = csgoFontsFolder + "\\conf.d";
Expand Down Expand Up @@ -517,6 +529,8 @@ private void apply_button_Click(object sender, EventArgs e)
MessageBox.Show($"Successfully applied {listBox1.SelectedItem}!" +
(csgoIsRunning ? "\n\nRestart CS:GO for the font to take effect." : ""),
"Font Applied!", MessageBoxButtons.OK, MessageBoxIcon.Information);

Settings.ActiveFont = listBox1.SelectedItem.ToString();
}
else
{
Expand Down Expand Up @@ -604,7 +618,7 @@ private void apply_button_Click(object sender, EventArgs e)
public static void LoadCSGOFolder(bool manual = false)
{

if (Settings.csgoPath != null) csgoFontsFolder = Settings.csgoPath + @"\csgo\panorama\fonts";
if (Settings.CsgoPath != null) csgoFontsFolder = Settings.CsgoPath + @"\csgo\panorama\fonts";
else
{
string csgoPath = tryLocatingCSGOFolder();
Expand All @@ -623,7 +637,7 @@ public static void LoadCSGOFolder(bool manual = false)
"Path Found!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
SetupFolderStructure(); // Make sure all folders exists...
Settings.csgoPath = csgoPath;
Settings.CsgoPath = csgoPath;
LoadCSGOFolder(); // Update the csgo fonts folder path
}
else
Expand Down Expand Up @@ -756,7 +770,7 @@ public static void AddFont(byte[] fontBytes)
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
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" +
"Current CS:GO Folder: " + Settings.csgoPath + "\n\nAre you sure you want to reset Font Manager?", "Reset?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
"Current CS:GO Folder: " + Settings.CsgoPath + "\n\nAre you sure you want to reset Font Manager?", "Reset?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
Directory.Delete(DataPath, true);
LoadCSGOFolder();
Expand Down Expand Up @@ -854,7 +868,8 @@ void insertAt(int index)
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save settings
SettingsManager.Save(Settings);
if (Settings != null)
SettingsManager.Save(Settings);
}
}
}
1 change: 1 addition & 0 deletions CSGO Font Manager/JsonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public T Load()
public void Save(T Data)
{
string json = JsonConvert.SerializeObject(Data, Formatting.Indented);
(new FileInfo(_targetFile)).Directory.Create();
File.WriteAllText(_targetFile, json);
}
}
Expand Down
7 changes: 4 additions & 3 deletions CSGO Font Manager/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace CSGO_Font_Manager
{
public class Settings
{
public string csgoPath { get; set; }
public bool proTips { get; set; } = true;
public string hideNewVersions { get; set; }
public string CsgoPath { get; set; }
public bool ProTips { get; set; } = true;
public string HideNewVersions { get; set; }
public string ActiveFont { get; set; }
}
}
Binary file removed CSGO Font Manager/bin/Debug/CSGO Font Manager.exe
Binary file not shown.
Binary file removed CSGO Font Manager/bin/Debug/CSGO Font Manager.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects
C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects\Font-Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.CoreCompileInputs.cache
C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects\Font-Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.exe
C:\Users\ewr0327\Google Drive (william.ragstad@gmail.com)\- Programming Projects\Font-Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.pdb
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\CSGO Font Manager.exe.config
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\CSGO Font Manager.exe
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\CSGO Font Manager.pdb
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\ActiproSoftware.Shared.WinForms.dll
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\ActiproSoftware.SyntaxEditor.WinForms.dll
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Newtonsoft.Json.dll
Expand All @@ -24,5 +21,9 @@ D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\C
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.GenerateResource.cache
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.CoreCompileInputs.cache
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csproj.CopyComplete
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.exe
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.pdb
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\CSGO Font Manager.csprojAssemblyReference.cache
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Font Manager.exe.config
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Font Manager.exe
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\bin\Debug\Font Manager.pdb
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\Font Manager.exe
D:\Documents\Visual Studio repos\CSGO Font Manager\CSGO Font Manager\obj\Debug\Font Manager.pdb
Binary file not shown.
Binary file removed CSGO Font Manager/obj/Debug/CSGO Font Manager.exe
Binary file not shown.
Binary file removed CSGO Font Manager/obj/Debug/CSGO Font Manager.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion CSGO Font Manager/stableVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2
3.3
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,44 @@
<div align=center>
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/WilliamRagstad/Font-Manager">
<img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/WilliamRagstad/Font-Manager/total">
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/WilliamRagstad/Font-Manager">
<img alt="GitHub Release Date" src="https://img.shields.io/github/release-date/WilliamRagstad/Font-Manager?color=green">
</div>


> ## Install



> ## Quick Install
>
> [Direct download](https://github.com/WilliamRagstad/Font-Manager/releases/latest/download/FontManager.exe) the latest version, or view all releases [here](https://github.com/WilliamRagstad/Font-Manager/releases).
> ---




# Introduction

**Font Manager** is a software designed to simplify switching between different custom fonts for CS:GO.

It features a "Drag-and-Drop" system which allows you to add new fonts in seconds. This software is safe to use and is completely VAC free.
It features a "Drag-and-Drop" system which allows you to add new fonts in seconds. This software is safe to use and is completely VAC safe.

#### Features:

- Easy font management!
- Drag and drop to add new fonts!
- Add already installed system fonts
- One click font removal
- **Support for the new panorama update!**

> Just take me to the [installation](#Install)...
- Easy font management
- Drag and drop to add fonts
- Add any system font
- One click font removal
- Support for the new panorama update

## Videos
## Video

<div align=center>

[![BananaGaming](https://img.youtube.com/vi/3xToNTtdmME/0.jpg)](https://www.youtube.com/watch?v=3xToNTtdmME)

[![Tutorial](https://img.youtube.com/vi/MhOnvkEIy1k/0.jpg)](https://www.youtube.com/watch?v=MhOnvkEIy1k)

(Outdated)

</div>


Expand Down
Loading

0 comments on commit c2dbcdd

Please sign in to comment.