Skip to content

Commit

Permalink
Add exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hbivnm committed Jan 5, 2023
1 parent 6ce9b97 commit cea9fb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Check out the releases and download [here](https://github.com/hbivnm/Venom-Cross

1. Download the latest release found [here](https://github.com/hbivnm/Venom-Crosshairs/releases).
2. Extract the folder named `VenomCrosshairs` to a directory of your liking.
3. Run Venom Crosshairs and customize your weapon-specific crosshair config.
3. Run `VenomCrosshairs.exe` and customize your weapon-specific crosshair config.
4. Hit Install/Update.
5. Set `cl_crosshair_file ""` in Team Fortress 2.

Expand All @@ -24,14 +24,14 @@ See the [wiki](https://github.com/hbivnm/Venom-Crosshairs/wiki).

# The future of Venom Crosshairs
## Planned features
- [ ] Add detection for "no explosion" .vpk files (see why [here](https://github.com/hbivnm/Venom-Crosshairs/wiki/FAQ))
- [ ] Add user-friendly prompts for currently (very rare) unhandled exceptions.
- [ ] Add notification indicator to "Reload crosshair list" button when new crosshairs are available. (Replaces popup message)
- [ ] Add double-clicking a weapon in the ListView should select it as "current weapon". (Note to self: add "class" listviewentry)
- [ ] Add "Update Venom Crosshairs" notification when new release is available.
- [ ] Detect if non-Venom Crosshair config is present and ask user if user wants to rename folder. (This will probably mark the official 1.0 release)

## Implemented features
- [x] Add user-friendly prompts for currently (very rare) unhandled exceptions.
- [x] Add detection for "no explosion" .vpk files (see why [here](https://github.com/hbivnm/Venom-Crosshairs/wiki/FAQ))
- [x] Automatically rename old config folders from previous Venom Crosshairs releases.
- [x] Change checkbox logic to toggle between adding to "ALL" or adding to "_CLASS_" (ex.) "ALL primary weapons for _CLASS_".
- [x] Add current version label.
Expand Down
27 changes: 23 additions & 4 deletions VenomCrosshairs/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace VenomCrosshairs
{
public partial class FormMain : Form
{
private static readonly string VC_VERSION = "beta8.2";
private static readonly string VC_VERSION = "beta9.0";

private static readonly string VC_CONFIG_NAME = "VenomCrosshairsConfig";

Expand Down Expand Up @@ -504,17 +504,28 @@ private void initVC()
{
cbExplosionEffect.SelectedIndex = Convert.ToInt32(File.ReadAllText(PATH_VC_RESOURCES_VC_EXPLOSION_EFFECT_CFG_FILE));
}
catch (Exception)
catch (Exception ex)
{
throw new FormatException($@"The contents of {PATH_VC_RESOURCES_VC_EXPLOSION_EFFECT_CFG_FILE} could not be parsed to an Integer.");
MessageBox.Show($"User setting file for \"Explosion effect\" could not be parsed to an Integer.\n\nExplosion effect restored to default.\n\nFor developer: Exception: {ex.Message}", "Venom Crosshairs - Could not parse user setting: Explosion effect", MessageBoxButtons.OK, MessageBoxIcon.Error);
File.Delete(PATH_VC_RESOURCES_VC_EXPLOSION_EFFECT_CFG_FILE);
}
else
cbExplosionEffect.SelectedIndex = 0;
cbExplosionEffect.SelectedIndexChanged += new EventHandler(onCBExplosionEffectChangeEvent);

// User TF2 path
if (File.Exists(PATH_VC_RESOURCES_VC_USERPATH_CFG_FILE))
textBoxTF2Path.Text = File.ReadAllText(PATH_VC_RESOURCES_VC_USERPATH_CFG_FILE);
{
try
{
textBoxTF2Path.Text = File.ReadAllText(PATH_VC_RESOURCES_VC_USERPATH_CFG_FILE);
performSanityCheck(textBoxTF2Path.Text);
}
catch (Exception ex)
{
MessageBox.Show($"User setting file for \"TF2 path\" could not be parsed to a String.\n\nTF2 path has been reset.\n\nFor developer: Exception: {ex.Message}", "Venom Crosshairs - Could not parse user setting: TF2 path", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

// Look for old configs from previous versions
renameOldConfig();
Expand Down Expand Up @@ -865,6 +876,9 @@ private void performInstallation(bool removeOldConfig)
if (File.Exists(fullScriptPath))
File.Delete(fullScriptPath);

try
{

File.WriteAllText(
$@"{textBoxTF2Path.Text}\tf\custom\{VC_CONFIG_NAME}\scripts\{weaponScriptName}",
File.ReadAllText($@"{PATH_VC_RESOURCES_SCRIPTS}\{weaponScriptName}")
Expand All @@ -873,6 +887,11 @@ private void performInstallation(bool removeOldConfig)
.Replace("VC_PLACEHOLDER_EXPLOSION_WATER_EFFECT", getExplosionWaterEffectParticleName(cbExplosionEffect.Text))
.Replace("VC_PLACEHOLDER", crosshair)
);
}
catch (Exception ex)
{
MessageBox.Show($"Something went terribly wrong! Please tell HbiVnm by adding him on Steam or creating a GitHub issue!\n\nFor developer: Exception: {ex.Message}", "Venom Crosshairs - Failed to get explosion particle name", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}));
writeLineToDebugger("Done!");
Expand Down

0 comments on commit cea9fb7

Please sign in to comment.