Skip to content
Permalink
Browse files

improved bad checksum file reporting; catch PlatformNotSupportExcepti…

…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 99ee2eb5b3a3ff6f81ca70bc989581a0d717c623
@@ -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)))
)
{
}
}
}
@@ -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))
@@ -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)
{
@@ -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);
}
}

@@ -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)
{
@@ -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);
}
}

@@ -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);

@@ -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;
@@ -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);
@@ -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.*")]
@@ -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" />
@@ -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

0 comments on commit 99ee2eb

Please sign in to comment.
You can’t perform that action at this time.