Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioseba Palop authored and iosebyte committed Jul 16, 2019
1 parent feef75c commit 79499ce
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 69 deletions.
28 changes: 14 additions & 14 deletions FOCA/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,13 +1017,13 @@ public void TreeViewProjectAfterSelect(object sender, TreeViewEventArgs e)
var h = (History)e.Node.Nodes["History"].Tag;
foreach (var hi in h.Items)
{
if (string.IsNullOrEmpty(hi.Author.Trim()))
if (String.IsNullOrWhiteSpace(hi.Author))
NewItemListView("Author", hi.Author, "History");

if (string.IsNullOrEmpty(hi.Comments.Trim()))
if (String.IsNullOrWhiteSpace(hi.Comments))
NewItemListView("Comments", hi.Comments, "History");

if (string.IsNullOrEmpty(hi.Path.Trim()))
if (String.IsNullOrWhiteSpace(hi.Path))
NewItemListView("Path", hi.Path, "History");
}
}
Expand Down Expand Up @@ -1499,16 +1499,16 @@ private void SetOldVersionNodes(TreeViewEventArgs e)

foreach (var vai in va.Items)
{
if (string.IsNullOrEmpty(vai.Author.Trim()))
if (String.IsNullOrEmpty(vai.Author))
NewItemListView("Author", vai.Author, valueOldVersion);

if (string.IsNullOrEmpty(vai.Comments.Trim()))
if (String.IsNullOrEmpty(vai.Comments))
NewItemListView("Comments", vai.Comments, valueOldVersion);

if (vai.SpecificDate)
NewItemListView("Date", vai.Date.ToString(), valueOldVersion);

if (string.IsNullOrEmpty(vai.Path.Trim()))
if (String.IsNullOrEmpty(vai.Path))
NewItemListView("Path", vai.Path, valueOldVersion);
}
}
Expand All @@ -1525,13 +1525,13 @@ private void SetHistoryNode(TreeViewEventArgs e)
var historyItems = (History)e.Node.Tag;
foreach (var hi in historyItems.Items)
{
if (hi.Author != null && hi.Author.Trim() != string.Empty)
if (!String.IsNullOrWhiteSpace(hi.Author))
NewItemListView("Author", hi.Author, historyValue);

if (hi.Comments != null && hi.Comments.Trim() != string.Empty)
if (!String.IsNullOrWhiteSpace(hi.Comments))
NewItemListView("Comments", hi.Comments, historyValue);

if (hi.Path != null && hi.Path.Trim() != string.Empty)
if (!String.IsNullOrWhiteSpace(hi.Path))
NewItemListView("Path", hi.Path, historyValue);
}
}
Expand All @@ -1548,16 +1548,16 @@ private void SetOldVersionNode(TreeViewEventArgs e)
var va = (OldVersions)e.Node.Tag;
foreach (var vai in va.Items)
{
if (vai.Author != null && vai.Author.Trim() != string.Empty)
if (!String.IsNullOrWhiteSpace(vai.Author))
NewItemListView("Author", vai.Author, oldVersionValue);

if (vai.Comments != null && vai.Comments.Trim() != string.Empty)
if (!String.IsNullOrWhiteSpace(vai.Comments))
NewItemListView("Comments", vai.Comments, oldVersionValue);

if (vai.SpecificDate)
NewItemListView("Date", vai.Date.ToString(), oldVersionValue);

if (vai.Path != null && vai.Path.Trim() != string.Empty)
if (!String.IsNullOrWhiteSpace(vai.Path))
NewItemListView("Path", vai.Path, oldVersionValue);
}
}
Expand All @@ -1568,10 +1568,10 @@ private void SetOldVersionNode(TreeViewEventArgs e)
/// <param name="e"></param>
private void SetOtherMetadataNode(TreeViewEventArgs e)
{
var otherMetaValue = "Other Metadata";
string otherMetaValue = "Other Metadata";

panelInformation.lvwInformation.Groups.Add("Other Metadata", "Other Metadata");
var metaDatadosValue = (MetaData)e.Node.Tag;
MetaData metaDatadosValue = (MetaData)e.Node.Tag;

if (metaDatadosValue.Applications != null && metaDatadosValue.Applications.Items.Count > 0)
foreach (var aplicacion in metaDatadosValue.Applications.Items)
Expand Down
4 changes: 2 additions & 2 deletions FOCA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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("3.4.5.0")]
[assembly: AssemblyFileVersion("3.4.5.0")]
[assembly: AssemblyVersion("3.4.5.5")]
[assembly: AssemblyFileVersion("3.4.5.5")]
40 changes: 21 additions & 19 deletions MetadataExtractCore/Analysis/PathAnalysis.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MetadataExtractCore.Utilities;
using System;

namespace MetadataExtractCore.Analysis
{
Expand All @@ -18,7 +15,7 @@ public static string ExtractUserFromPath(string pathValue)
string resultUser;

if (GetUserFromPathValue(pathValue, @":\winnt\profiles\", out resultUser)) return resultUser;

if (GetUserFromPathValue(pathValue, @":\documents and settings\", out resultUser)) return resultUser;

if (GetUserFromPathValue(pathValue, @":\dokumente und einstellungen\", out resultUser)) return resultUser;
Expand Down Expand Up @@ -68,14 +65,14 @@ public static bool IsValidPath(string pathValue)
pathValue = pathValue.ToLower();
if (!Functions.StringContainAnyLetter(pathValue))
return false;

if (pathValue.Length > 2 && char.IsLetter(pathValue[0]) && pathValue[1] == ':' && pathValue[2] == '\\')
return true;

if (pathValue.StartsWith("\\\\") &&
pathValue.Length > 2 && pathValue[2] != '\\')
return true;

if (pathValue.StartsWith("\\") &&
pathValue.Length > 1 && pathValue[1] != '\\')
return true;
Expand Down Expand Up @@ -109,7 +106,7 @@ public static string RemoveNamePath(string pathValue)
return pathValue.Remove(pathValue.LastIndexOf('\\') + 1);
if (pathValue.LastIndexOf('/') > pathValue.LastIndexOf('\\') && pathValue.LastIndexOf('/') < pathValue.Length - 1)
return pathValue.Remove(pathValue.LastIndexOf('/') + 1);

return pathValue;
}

Expand All @@ -120,19 +117,24 @@ public static string RemoveNamePath(string pathValue)
/// <returns></returns>
public static string CleanPath(string pathValue)
{
var uriValue = new Uri(pathValue);
pathValue = uriValue.AbsoluteUri;

pathValue = RemoveNamePath(pathValue);

if (pathValue.IndexOf("file://") != -1)
pathValue = pathValue.Substring(pathValue.IndexOf("file://") + 7, pathValue.Length - pathValue.IndexOf("file://") - 7);
if (pathValue.IndexOf(':') != 2) return IsValidPath(pathValue) ? pathValue.Trim() : string.Empty;
if (Uri.TryCreate(pathValue, UriKind.Absolute, out Uri uriValue))
{
pathValue = uriValue.AbsoluteUri;
pathValue = RemoveNamePath(pathValue);
if (pathValue.IndexOf("file://") != -1)
pathValue = pathValue.Substring(pathValue.IndexOf("file://") + 7, pathValue.Length - pathValue.IndexOf("file://") - 7);
if (pathValue.IndexOf(':') != 2)
return IsValidPath(pathValue) ? pathValue.Trim() : String.Empty;

pathValue = pathValue.Replace('/', '\\');
pathValue = pathValue.Substring(1, pathValue.Length - 1);
pathValue = pathValue.Replace('/', '\\');
pathValue = pathValue.Substring(1, pathValue.Length - 1);

return IsValidPath(pathValue) ? pathValue.Trim() : string.Empty;
return IsValidPath(pathValue) ? pathValue.Trim() : String.Empty;
}
else
{
return String.Empty;
}
}
}
}
2 changes: 1 addition & 1 deletion MetadataExtractCore/Metadata/EXIFDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override void analyzeFile()
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Error analizing EXIF metadata ({0})", e.ToString());
System.Diagnostics.Debug.WriteLine($"Error analizing EXIF metadata ({e.ToString()})");
}
finally
{
Expand Down
65 changes: 33 additions & 32 deletions MetadataExtractCore/Metadata/Office972003.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using MetadataExtractCore.Analysis;
using MetadataExtractCore.Diagrams;
using MetadataExtractCore.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using MetadataExtractCore.Utilities;
using MetadataExtractCore.Analysis;
using MetadataExtractCore.Diagrams;

namespace MetadataExtractCore.Metadata
{
Expand All @@ -20,7 +20,7 @@ public Office972003()
dicPictureEXIF = new SerializableDictionary<string, EXIFDocument>();
}

public Office972003(Stream stm): this()
public Office972003(Stream stm) : this()
{
this.stm = new MemoryStream();
Functions.CopyStream(stm, this.stm);
Expand Down Expand Up @@ -189,7 +189,7 @@ private void GetPrintersInXls(OleDocument doc)
return;
BinaryReader br = new BinaryReader(Workbook);
Workbook.Seek(0, SeekOrigin.Begin);
while (Workbook.Position <= Workbook.Length - 2)
while (Workbook.Position <= Workbook.Length - 4)
{
try
{
Expand All @@ -200,14 +200,14 @@ private void GetPrintersInXls(OleDocument doc)
if (Tipo == 0x4D)
{
long PosOri = Workbook.Position;
if (br.ReadInt16() == 0)
if (br.ReadInt16() == 0)
{
String PrinterName = Encoding.Unicode.GetString(br.ReadBytes(32 * 2)).Replace('\0', ' ');
br.ReadInt16();
br.ReadInt16();
Int16 StructSize = br.ReadInt16();
Int16 DriverSize = br.ReadInt16();

if (DriverSize != 0)
{
Workbook.Seek(StructSize - (8 + 64), SeekOrigin.Current);
Expand All @@ -233,7 +233,7 @@ private void GetPrintersInXls(OleDocument doc)
}
}

private void GetHistory(OleDocument doc)
private void GetHistory(OleDocument doc)
{
using (Stream WordDocument = doc.OpenStream("WordDocument"))
{
Expand Down Expand Up @@ -323,29 +323,36 @@ private void GetOperatingSystem(OleDocument doc)
case 4:
switch (intLowVersion)
{
case 0: FoundMetaData.OperativeSystem = "Windows NT 4.0";
case 0:
FoundMetaData.OperativeSystem = "Windows NT 4.0";
break;
case 10: FoundMetaData.OperativeSystem = "Windows 98";
case 10:
FoundMetaData.OperativeSystem = "Windows 98";
break;
}
break;
case 5:
switch (intLowVersion)
{
case 0: FoundMetaData.OperativeSystem = "Windows Server 2000";
case 0:
FoundMetaData.OperativeSystem = "Windows Server 2000";
break;
case 1: FoundMetaData.OperativeSystem = "Windows XP";
case 1:
FoundMetaData.OperativeSystem = "Windows XP";
break;
case 2: FoundMetaData.OperativeSystem = "Windows Server 2003";
case 2:
FoundMetaData.OperativeSystem = "Windows Server 2003";
break;
}
break;
case 6:
switch (intLowVersion)
{
case 0: FoundMetaData.OperativeSystem = "Windows Vista";
case 0:
FoundMetaData.OperativeSystem = "Windows Vista";
break;
case 1: FoundMetaData.OperativeSystem = "Windows 7";
case 1:
FoundMetaData.OperativeSystem = "Windows 7";
break;
}
break;
Expand All @@ -354,7 +361,8 @@ private void GetOperatingSystem(OleDocument doc)

private void GetPathPpt(OleDocument doc)
{
using (var WordDocument = doc.OpenStream("PowerPoint Document")) {
using (var WordDocument = doc.OpenStream("PowerPoint Document"))
{
if (WordDocument == null)
return;
try
Expand Down Expand Up @@ -424,7 +432,7 @@ private void GetImagesDoc(OleDocument doc)
}
}

List<int> lstJPEG = Functions.SearchBytesInBytes(bufferPIC, new byte[] { 0xFF, 0xD8 });
List<int> lstJPEG = Functions.SearchBytesInBytes(bufferPIC, new byte[] { 0xFF, 0xD8, 0xFF });
if (lstJPEG.Count > 0)
{
using (MemoryStream msJPG = new MemoryStream(bufferPIC, lstJPEG[0], bufferPIC.Length - lstJPEG[0]))
Expand Down Expand Up @@ -468,17 +476,13 @@ private void GetImagesPpt(OleDocument doc)
if (PICLength == 0 || stmPictures.Position + PICLength > stmPictures.Length) break;
byte[] bufferPIC = brData.ReadBytes((int)PICLength);
string strImageName = "Image" + ImagesFound++;

using (MemoryStream msJPG = new MemoryStream(bufferPIC, 0x11, bufferPIC.Length - 0x11))
{
EXIFDocument eDoc = new EXIFDocument(msJPG, ".jpg");

eDoc.analyzeFile();
eDoc.Close();
if (eDoc.Thumbnail != null)
lon += eDoc.Thumbnail.Length;
cont++;
System.Diagnostics.Debug.WriteLine(cont.ToString());
System.Diagnostics.Debug.WriteLine(lon /(1024*1024) + " Megacas");

dicPictureEXIF.Add(strImageName, eDoc);

Expand All @@ -496,9 +500,6 @@ private void GetImagesPpt(OleDocument doc)
}
}

static int cont = 0;
static long lon = 0;

private void GetLinksBinary(OleDocument doc)
{
var pending = new List<Action>() {
Expand Down Expand Up @@ -566,9 +567,9 @@ private void GetLinksBinaryWorkbook(Stream document)
continue;

string aux = link;
aux = aux.Trim(new char[] { (char)18 });
aux = aux.Trim(new char[] { (char)18 });

if (!link.EndsWith("/"))
if (!link.EndsWith("/"))
{
int cuentaSlash = 0;
for (int i = 0; i < aux.Length; i++)
Expand Down Expand Up @@ -603,7 +604,7 @@ private void GetLinksBinaryPowerPointDocument(Stream document)
}


private bool IsInterestingLink(string href)
private bool IsInterestingLink(string href)
{
if (href != string.Empty)
{
Expand Down Expand Up @@ -642,9 +643,9 @@ private bool IsInterestingLink(string href)
return true;
}
}
catch (UriFormatException)
catch (UriFormatException)
{
if (!href.StartsWith("#"))
if (!href.StartsWith("#"))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractCore/Metadata/OpenOfficeDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private void analizeFileMeta(Stream stm)
foreach (XmlNode xn in xnl)
FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.Attributes.GetNamedItem("xlink:href").Value), true);
xnl = doc.GetElementsByTagName("meta:document-statistic");
if (xnl != null)
if (xnl != null && xnl.Count > 0)
{
String estadisticas = string.Empty;
if (xnl[0].Attributes.GetNamedItem("meta:table-count") != null)
Expand Down

0 comments on commit 79499ce

Please sign in to comment.