Skip to content

Commit

Permalink
Merge pull request #8 from WilliamRagstad/master
Browse files Browse the repository at this point in the history
Fixed Settings stored in one file and removed Auto Update
  • Loading branch information
WilliamRagstad authored Dec 8, 2019
2 parents 81365cf + 9a406cd commit 54f4e45
Show file tree
Hide file tree
Showing 46 changed files with 94,125 additions and 82 deletions.
88 changes: 75 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,76 @@

CSGO Font Manager/Resources/drop your file here.png
CSGO Font Manager/Resources/drop your font here.png
CSGO Font Manager/Resources/fadeout_blue.png
CSGO Font Manager/Resources/fontmanager.png
CSGO Font Manager/Resources/fontmanager_watermark.png
CSGO Font Manager/Resources/FontReg.exe
CSGO Font Manager/Resources/Thumbnail (2).png
CSGO Font Manager/Resources/Thumbnail.jpg
CSGO Font Manager/Resources/Thumbnail.png
CSGO Font Manager/obj/Release/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
CSGO Font Manager/obj/Release/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
CSGO Font Manager/obj/Release/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
.vs/*
CSGO Font Manager/Resources/*
CSGO Font Manager/obj/Release/*
.vs/*

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Roslyn cache directories
*.ide/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
*.pfx
*.exe
CSGO Font Manager/obj/Debug/CSGO Font Manager.exe
20 changes: 19 additions & 1 deletion CSGO Font Manager/CSGO Font Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,29 @@
</PropertyGroup>
<PropertyGroup />
<PropertyGroup />
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>D4FDEF984D1A0C754B094CB55EEEF128D4012AF8</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>
</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<ItemGroup>
<Reference Include="ActiproSoftware.Shared.WinForms, Version=18.1.341.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763" />
<Reference Include="ActiproSoftware.SyntaxEditor.WinForms, Version=18.1.341.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763, processorArchitecture=MSIL" />
<Reference Include="Fastenshtein, Version=1.0.0.5, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Fastenshtein.1.0.0.5\lib\net40-client\Fastenshtein.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -86,6 +102,8 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="JsonManager.cs" />
<Compile Include="Settings.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -94,6 +112,7 @@
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -130,7 +149,6 @@
<ItemGroup>
<Content Include="fonmanager_icon.ico" />
<None Include="Resources\fonmanager_icon-5.png" />
<None Include="Resources\FontManagerUpdater.exe" />
<None Include="Resources\add_retro.png" />
<None Include="Resources\remove_retro.png" />
<Content Include="stableVersion.txt" />
Expand Down
1 change: 1 addition & 0 deletions CSGO Font Manager/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 66 additions & 49 deletions CSGO Font Manager/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
Expand All @@ -16,27 +17,27 @@ namespace CSGO_Font_Manager
{
public partial class Form1 : Form
{
public static string VersionNumber = "3.0"; // Remember to update stableVersion.txt when releasing a new stable update.
public static string VersionNumber = "3.1"; // 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 FontManagerFolder = HomeFolder + @"Font Manager\";
public static string FontsFolder = FontManagerFolder + @"Fonts\";
public static string DataPath = FontManagerFolder + @"Data\";
public static string UpdaterPath = DataPath + "FontManagerUpdater.exe";
public static string FirstStartupPath = DataPath + "firstStartup.txt";

protected static string UpdaterToken = "cf38519aeddfb438e69e1f8a4b1412dd";
private string SettingsFile = DataPath + "settings.json";

public static string csgoFolder = null;
public static Settings Settings;
public static JsonManager<Settings> SettingsManager;

public static string csgoFontsFolder = null;
public static bool isFirstStartup = true;

public static string defaultFontName = "Default Font";

public static string fontPreviewText = "The quick brown fox jumps over the lazy dog. 100 - + / = 23.5";

public static FormViews CurrentFormView = FormViews.Main;
private static PrivateFontCollection _privateFontCollection = new PrivateFontCollection();

public enum FormViews
{
Expand All @@ -53,25 +54,16 @@ private void Form1_Load(object sender, EventArgs e)
{
AutoFocusRunningInstance();
version_label.Text = "Version " + VersionNumber;

SetupFolderStructure();

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

checkForUpdates();
LoadCSGOFolder();
refreshFontList();

// Check if first startup
if (File.Exists(FirstStartupPath))
{
isFirstStartup = File.ReadAllText(FirstStartupPath) != "1";
File.WriteAllText(FirstStartupPath, "1");
}
else
{
isFirstStartup = true;
File.WriteAllText(FirstStartupPath, "1");
}


// Update all texts
switchView(FormViews.Main);
}
Expand All @@ -83,29 +75,52 @@ private void AutoFocusRunningInstance()

private void checkForUpdates()
{
// Extract the updater binary
string versionPattern = @"(\d+\.)(\d+\.?)+";

// Get new version
string newVersion = null;
try
{
if (!File.Exists(UpdaterPath)) File.WriteAllBytes(UpdaterPath, Properties.Resources.FontManagerUpdater);
var webRequest = WebRequest.Create(CurrentVersion);

using (var response = webRequest.GetResponse())
using(var content = response.GetResponseStream())
using(var reader = new StreamReader(content)){
newVersion = reader.ReadToEnd().Replace("\n","");


}
}
catch { }

string programPath = System.Reflection.Assembly.GetEntryAssembly().Location; // Get the location where the program (.exe) was started from
ProcessStartInfo psi = new ProcessStartInfo(UpdaterPath, $"\"{UpdaterToken}\" \"{VersionNumber}\" \"{programPath}\"");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
var p = Process.Start(psi);
p.WaitForExit();
string response = p.StandardOutput.ReadToEnd();
string errors = p.StandardError.ReadToEnd();

if (!string.IsNullOrWhiteSpace(errors))
catch (Exception e)
{
// throw new Exception(errors);
// User is probably offline
Console.WriteLine(e);
}

if (!Regex.IsMatch(newVersion, versionPattern))
{
Console.WriteLine("New version number is in an invalid format.");
return;
}

string rawLocalVersion = VersionNumber.Remove(VersionNumber.IndexOf('.') ,1).Replace(".",",").Split(' ')[0]; // Split in case version
string rawNewVersion = newVersion.Remove(newVersion.IndexOf('.') ,1).Replace(".",",").Split(' ')[0]; // number contains "2.2 Alpha"
// Convert to a comparable number
float localVersionRepresentation = float.Parse(rawLocalVersion);
float newVersionRepresentation = float.Parse(rawNewVersion);

if (VersionNumber.Trim() != newVersion.Trim() && newVersionRepresentation > localVersionRepresentation)
{
// New updated version is released

if (MessageBox.Show(
$"Version {newVersion} is available to download from the official GitHub Repo!\n\n" +
"Do you want to continue getting update notifications?",
"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
{
Settings.BlockNoficationsForVersion = VersionNumber;
}
}
}

private static void SetupFolderStructure()
Expand Down Expand Up @@ -177,9 +192,10 @@ private void showFontPreview()

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

switchView(FormViews.AddSystemFont);
Expand Down Expand Up @@ -336,7 +352,6 @@ private void refreshFontList()
if (IsFontExtension(Path.GetExtension(file)))
{
// _privateFontCollection.AddFontFile(file);

AddFont(foldername, file);
}
}
Expand Down Expand Up @@ -385,7 +400,7 @@ private void apply_button_Click(object sender, EventArgs e)
{

//Get the csgo path (home folder...) if data file not found...
if (csgoFolder != null)
if (Settings.CSGOPath != null)
{
// Make sure the folders exists
string csgoConfD = csgoFontsFolder + "\\conf.d";
Expand Down Expand Up @@ -535,8 +550,8 @@ public static void LoadCSGOFolder(bool manual = false)
string csgoDataPath = DataPath + @"\csgopath.dat";
if (File.Exists(csgoDataPath))
{
csgoFolder = File.ReadAllText(csgoDataPath);
csgoFontsFolder = csgoFolder + @"\csgo\panorama\fonts";
Settings.CSGOPath = File.ReadAllText(csgoDataPath);
csgoFontsFolder = Settings.CSGOPath + @"\csgo\panorama\fonts";
}
else
{
Expand Down Expand Up @@ -610,8 +625,6 @@ private static string tryLocatingCSGOFolder()

#region Font Management

private static PrivateFontCollection _privateFontCollection = new PrivateFontCollection();

public static FontFamily GetFontFamilyByName(string name) // name = LemonMilk
{
// This is probably unesessary
Expand All @@ -624,8 +637,6 @@ public static FontFamily GetFontFamilyByName(string name) // name = LemonMilk
{
return StringSimilarity(name, x.Name) > 0.75f;
});

return null;
}

private static float StringSimilarity(string a, string b)
Expand Down Expand Up @@ -690,7 +701,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: " + csgoFolder + "\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 @@ -732,5 +743,11 @@ private void fontPreview_richTextBox_TextChanged(object sender, EventArgs e)
{

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save settings
SettingsManager.Save(Settings);
}
}
}
Loading

0 comments on commit 54f4e45

Please sign in to comment.