Skip to content

Commit

Permalink
improved bad checksum file reporting; catch PlatformNotSupportExcepti…
Browse files Browse the repository at this point in the history
…on on startup and display OS requirements (XP SP3, Vista SP2, Win7); have \n in language files interpreted as Environment.NewLine (\r\n); change version # to 1.11.*
  • Loading branch information
judwhite committed Aug 25, 2011
1 parent faeee75 commit 99ee2eb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
19 changes: 19 additions & 0 deletions ilSFV/InvalidChecksumFileException.cs
@@ -0,0 +1,19 @@
using System;
using System.IO;
using System.Text;
using ilSFV.Localization;
using ilSFV.Model.Workset;

namespace ilSFV
{
class InvalidChecksumFileException : Exception
{
// TODO: Localize "Line"
public InvalidChecksumFileException(string fileName, ChecksumType checksumType, string[] lines, int lineIndex, int codePage)
: base(string.Format("Line {0}: \"{1}\"", lineIndex + 1, lines[lineIndex]) + Environment.NewLine + Environment.NewLine +
string.Format(Language.MainForm.FileContentsNotRecognized, fileName, checksumType, File.ReadAllText(fileName, Encoding.GetEncoding(codePage)))
)
{
}
}
}
2 changes: 1 addition & 1 deletion ilSFV/Localization/Language.cs
Expand Up @@ -116,7 +116,7 @@ private static void LoadFile(string path)
break;
propertyName += line[j];
}
string value = line.Substring(j).TrimStart(new[] { ' ', '=' }).Trim().Replace("\\n", "\n");
string value = line.Substring(j).TrimStart(new[] { ' ', '=' }).Trim().Replace("\\n", Environment.NewLine);

PropertyInfo pi = sectionType.GetProperty(propertyName, bf);
if (pi != null && !string.IsNullOrEmpty(value))
Expand Down
39 changes: 19 additions & 20 deletions ilSFV/MainForm.cs
Expand Up @@ -878,17 +878,18 @@ public bool LoadAndVerifyFile(string fileName, bool doVerify, bool getFileInfo)
if (line.StartsWith("MD5 ("))
{
int idx = line.LastIndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
chkFileName = line.Substring(5, idx - 5 - 3);
chkMD5 = line.Substring(idx + 1, line.Length - idx - 1);
if (chkMD5.Length != 32)
{
string allText = File.ReadAllText(fileName, Encoding.GetEncoding(CODE_PAGE));
throw new Exception(string.Format(Language.MainForm.FileContentsNotRecognized, fileName, "MD5", allText));
}
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
}
else
{
int idx = line.IndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);

if (idx == 32)
{
Expand All @@ -898,13 +899,12 @@ public bool LoadAndVerifyFile(string fileName, bool doVerify, bool getFileInfo)
else
{
idx = line.LastIndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
chkFileName = line.Substring(0, idx);
chkMD5 = line.Substring(idx + 1, line.Length - idx - 1);
if (chkMD5.Length != 32)
{
string allText = File.ReadAllText(fileName, Encoding.GetEncoding(CODE_PAGE));
throw new Exception(string.Format(Language.MainForm.FileContentsNotRecognized, fileName, "MD5", allText));
}
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
}
}

Expand All @@ -922,17 +922,18 @@ public bool LoadAndVerifyFile(string fileName, bool doVerify, bool getFileInfo)
if (line.StartsWith("SHA1 ("))
{
int idx = line.LastIndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
chkFileName = line.Substring(6, idx - 6 - 3);
chkSHA1 = line.Substring(idx + 1, line.Length - idx - 1);
if (chkSHA1.Length != 40)
{
string allText = File.ReadAllText(fileName, Encoding.GetEncoding(CODE_PAGE));
throw new Exception(string.Format(Language.MainForm.FileContentsNotRecognized, fileName, "SHA-1", allText));
}
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
}
else
{
int idx = line.IndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);

if (idx == 40)
{
Expand All @@ -942,13 +943,12 @@ public bool LoadAndVerifyFile(string fileName, bool doVerify, bool getFileInfo)
else
{
idx = line.LastIndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
chkFileName = line.Substring(0, idx);
chkSHA1 = line.Substring(idx + 1, line.Length - idx - 1);
if (chkSHA1.Length != 40)
{
string allText = File.ReadAllText(fileName, Encoding.GetEncoding(CODE_PAGE));
throw new Exception(string.Format(Language.MainForm.FileContentsNotRecognized, fileName, "SHA-1", allText));
}
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
}
}

Expand All @@ -961,6 +961,8 @@ public bool LoadAndVerifyFile(string fileName, bool doVerify, bool getFileInfo)
else if (set.Type == ChecksumType.SFV)
{
int idx = line.LastIndexOf(' ');
if (idx == -1)
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);
string chkSFV = line.Substring(idx + 1, line.Length - idx - 1);
string chkFileName = line.Substring(0, idx);

Expand All @@ -970,10 +972,7 @@ public bool LoadAndVerifyFile(string fileName, bool doVerify, bool getFileInfo)
chkSFV = chkSFV.Substring(2);

if (chkSFV.Length != 8)
{
string allText = File.ReadAllText(fileName, Encoding.GetEncoding(CODE_PAGE));
throw new Exception(string.Format(Language.MainForm.FileContentsNotRecognized, fileName, "SFV", allText));
}
throw new InvalidChecksumFileException(fileName, set.Type, lines, i, CODE_PAGE);

file.FileName = chkFileName;
file.OriginalChecksum = chkSFV;
Expand Down
6 changes: 6 additions & 0 deletions ilSFV/Program.cs
Expand Up @@ -166,6 +166,12 @@ static void Main(string[] args)
createMutex.ReleaseMutex();
}
}
catch (PlatformNotSupportedException)
{
// TODO: Localize
MessageBox.Show("This program requires Windows XP SP3, Windows Vista SP2, Windows 7 or later.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
catch (Exception ex)
{
ShowException(ex);
Expand Down
2 changes: 1 addition & 1 deletion ilSFV/Properties/AssemblyInfo.cs
Expand Up @@ -30,4 +30,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.10.*")]
[assembly: AssemblyVersion("1.11.*")]
1 change: 1 addition & 0 deletions ilSFV/ilSFV.csproj
Expand Up @@ -86,6 +86,7 @@
<DependentUpon>GetInputForm.cs</DependentUpon>
</Compile>
<Compile Include="Hash\SHA1.cs" />
<Compile Include="InvalidChecksumFileException.cs" />
<Compile Include="Localization\ExceptionForm.Generated.cs" />
<Compile Include="Localization\General.Generated.cs" />
<Compile Include="Localization\Language.cs" />
Expand Down
2 changes: 1 addition & 1 deletion ilsfv-setup.iss
Expand Up @@ -7,7 +7,7 @@
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{D463AB63-D949-4FB1-B586-968FBBE529D2}
AppName=ilSFV
AppVerName=ilSFV 1.10
AppVerName=ilSFV 1.11
AppPublisher=Jud White
AppPublisherURL=http://www.cdtag.com/ilsfv
AppSupportURL=http://www.cdtag.com/ilsfv
Expand Down

0 comments on commit 99ee2eb

Please sign in to comment.