Refactor - fix minor issues from codacy

This commit is contained in:
Nikolaj Olsson 2019-01-28 19:53:20 +01:00
parent 877541314c
commit 1b3314ccdf
9 changed files with 90 additions and 19 deletions

View File

@ -226,8 +226,6 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats
return false;
}
//Console.WriteLine(_stream.Position.ToString() + ", " + bytesleft.ToString());
// We have enough bytes, read
int fourCc;
int size;

View File

@ -27,14 +27,20 @@ namespace Nikse.SubtitleEdit.Core
if (reader.NodeType == XmlNodeType.Element)
{
if (!reader.IsEmptyElement && reader.Depth > 0)
{
name.Append('/').Append(reader.Name);
}
else if (reader.Depth == 0)
{
language.Name = reader["Name"];
}
}
else if (reader.NodeType == XmlNodeType.EndElement)
{
if (name.Length > 0)
{
name.Length -= reader.Name.Length + 1;
}
}
else if (reader.NodeType == XmlNodeType.Text)
{

View File

@ -1170,7 +1170,7 @@ namespace Nikse.SubtitleEdit.Forms
}
catch (Exception exception)
{
Console.WriteLine(exception);
System.Diagnostics.Debug.WriteLine(exception);
IncrementAndShowProgress();
}
index++;

View File

@ -33,7 +33,10 @@ namespace Nikse.SubtitleEdit.Forms
{
string title = Path.GetFileNameWithoutExtension(subtitleFileName) ?? string.Empty;
if (title.Length > 28)
{
title = title.Substring(0, 28);
}
textBoxTranslatedTitle.Text = title;
}

View File

@ -56,7 +56,9 @@ namespace Nikse.SubtitleEdit.Forms
private void CheckForUpdates_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void CheckForUpdates_Shown(object sender, EventArgs e)
@ -110,9 +112,13 @@ namespace Nikse.SubtitleEdit.Forms
_seconds += timerCheckForUpdates.Interval / TimeCode.BaseUnit;
if (buttonDownloadAndInstall.Visible)
{
buttonDownloadAndInstall.Focus();
}
else if (buttonOK.Visible)
{
buttonOK.Focus();
}
}
private void SetLargeSize()

View File

@ -8,14 +8,19 @@ namespace UpdateAssemblyInfo
public bool RunCommandAndGetOutput(string command, string arguments, string workingFolder)
{
var p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.Arguments = arguments;
p.StartInfo.WorkingDirectory = workingFolder;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
var p = new Process
{
StartInfo =
{
FileName = command,
Arguments = arguments,
WorkingDirectory = workingFolder,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
p.OutputDataReceived += OutputDataReceived;
try
@ -36,8 +41,10 @@ namespace UpdateAssemblyInfo
private void OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e != null && e.Data != null)
if (e?.Data != null)
{
Result = e.Data;
}
}
}
}

View File

@ -48,13 +48,7 @@ namespace UpdateAssemblyInfo
}
}
public string ShortVersion
{
get
{
return string.Format(CultureInfo.InvariantCulture, "{0:D}.{1:D}.{2:D}", Major, Minor, Maintenance);
}
}
public string ShortVersion => string.Format(CultureInfo.InvariantCulture, "{0:D}.{1:D}.{2:D}", Major, Minor, Maintenance);
public VersionInfo()
{
@ -65,9 +59,15 @@ namespace UpdateAssemblyInfo
{
var match = LongGitTagRegex.Match(version);
if (!match.Success)
{
match = LongVersionRegex.Match(version);
}
if (!match.Success)
{
match = ShortGitTagRegex.Match(version);
}
if (!match.Success || string.IsNullOrWhiteSpace(guid))
{
Build = UnknownBuild;
@ -79,9 +79,15 @@ namespace UpdateAssemblyInfo
RevisionGuid = guid.Trim().ToLowerInvariant();
}
if (!match.Success)
{
match = ShortVersionRegex.Match(version);
}
if (!match.Success)
{
throw new ArgumentException("Invalid version identifier: '" + version + "'");
}
Major = int.Parse(match.Groups["major"].Value, NumberStyles.None, CultureInfo.InvariantCulture);
Minor = int.Parse(match.Groups["minor"].Value, NumberStyles.None, CultureInfo.InvariantCulture);
Maintenance = string.IsNullOrEmpty(match.Groups["maintenance"].Value) ? 0 : int.Parse(match.Groups["maintenance"].Value, NumberStyles.None, CultureInfo.InvariantCulture);
@ -94,9 +100,14 @@ namespace UpdateAssemblyInfo
{
cmp = Major.CompareTo(vi.Major);
if (cmp == 0)
{
cmp = Minor.CompareTo(vi.Minor);
}
if (cmp == 0)
{
cmp = Maintenance.CompareTo(vi.Maintenance);
}
}
return cmp;
}
@ -152,7 +163,10 @@ namespace UpdateAssemblyInfo
translation.Load(fileName);
var node = translation.DocumentElement.SelectSingleNode("General/Version") as XmlElement;
if (node != null && node.InnerText.Trim() == oldVersion.ShortVersion)
{
node.InnerText = newVersion.ShortVersion;
}
translation.Save(fileName);
}
}
@ -327,7 +341,9 @@ namespace UpdateAssemblyInfo
{
var path = Path.Combine(p, "git.exe");
if (File.Exists(path))
{
return path;
}
}
}
@ -338,7 +354,9 @@ namespace UpdateAssemblyInfo
{
var path = Path.Combine(envProgramFiles, gitPath);
if (File.Exists(path))
{
return path;
}
}
envProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
@ -346,7 +364,9 @@ namespace UpdateAssemblyInfo
{
var path = Path.Combine(envProgramFiles, gitPath);
if (File.Exists(path))
{
return path;
}
}
var envSystemDrive = Environment.GetEnvironmentVariable("SystemDrive");
@ -358,15 +378,21 @@ namespace UpdateAssemblyInfo
{
var path = Path.Combine(envSystemDrive, "Program Files", gitPath);
if (File.Exists(path))
{
return path;
}
path = Path.Combine(envSystemDrive, "Program Files (x86)", gitPath);
if (File.Exists(path))
{
return path;
}
path = Path.Combine(envSystemDrive, gitPath);
if (File.Exists(path))
{
return path;
}
}
try
@ -376,15 +402,21 @@ namespace UpdateAssemblyInfo
{
var path = Path.Combine(cRoot, "Program Files", gitPath);
if (File.Exists(path))
{
return path;
}
path = Path.Combine(cRoot, "Program Files (x86)", gitPath);
if (File.Exists(path))
{
return path;
}
path = Path.Combine(cRoot, gitPath);
if (File.Exists(path))
{
return path;
}
}
}
catch (Exception exception)

View File

@ -38,14 +38,20 @@ namespace Nikse.SubtitleEdit.Core
if (reader.NodeType == XmlNodeType.Element)
{
if (!reader.IsEmptyElement && reader.Depth > 0)
{
name.Append('/').Append(reader.Name);
}
else if (reader.Depth == 0)
{
language.Name = reader[""Name""];
}
}
else if (reader.NodeType == XmlNodeType.EndElement)
{
if (name.Length > 0)
{
name.Length -= reader.Name.Length + 1;
}
}
else if (reader.NodeType == XmlNodeType.Text)
{

View File

@ -33,7 +33,9 @@ namespace UpdateResourceScript
{
var fileInfo = FileVersionInfo.GetVersionInfo(assemblyFileName);
if (fileInfo.OriginalFilename == null)
{
throw new Exception("File '" + assemblyFileName + "' is not an assembly file");
}
// Fixed-info properties
FileVersion = string.Format(CultureInfo.InvariantCulture, "{0:D}, {1:D}, {2:D}, {3:D}", fileInfo.FileMajorPart, fileInfo.FileMinorPart, fileInfo.FileBuildPart, fileInfo.FilePrivatePart);
@ -51,11 +53,19 @@ namespace UpdateResourceScript
// Optional string-information-block values
block.Append("\nVALUE \"InternalName\", TargetAssemblyFileName"); // Consistent with VS behaviour (differs from MSDN)
if (fileInfo.LegalTrademarks != null)
{
block.Append("LegalTrademarks", fileInfo.LegalTrademarks);
}
if (fileInfo.LegalCopyright != null)
{
block.Append("LegalCopyright", fileInfo.LegalCopyright);
}
if (fileInfo.Comments != null)
{
block.Append("Comments", fileInfo.Comments);
}
// Flagged string-information-block values
if (fileInfo.IsSpecialBuild && fileInfo.SpecialBuild != null)
{
@ -70,7 +80,10 @@ namespace UpdateResourceScript
StringFileInfo = block.Replace("\n", Environment.NewLine + new String(' ', 3 * 4 /* Indentation */)).ToString();
if (fileInfo.IsPreRelease)
{
flags.Add("VS_FF_PRERELEASE");
}
FileFlags = (flags.Count > 0) ? "(" + string.Join("|", flags) + ")" : "0L";
}
}