Skip to content

Commit

Permalink
Merge pull request #155 from Visionaid-International-Ltd/analyzer-fixes
Browse files Browse the repository at this point in the history
Analyzer fixes
  • Loading branch information
ironfede authored Sep 18, 2024
2 parents 56eff33 + 1c3bf3b commit b95add4
Show file tree
Hide file tree
Showing 28 changed files with 327 additions and 727 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenMcdf.Extensions.OLEProperties
{
public class DictionaryEntry
{
int codePage;
readonly int codePage;

public DictionaryEntry(int codePage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OpenMcdf.Extensions.OLEProperties
{
public class DictionaryProperty : IDictionaryProperty
{
private int codePage;
private readonly int codePage;

public DictionaryProperty(int codePage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class OLEPropertiesContainer

public PropertyContext Context { get; private set; }

private List<OLEProperty> properties = new List<OLEProperty>();
private readonly List<OLEProperty> properties = new List<OLEProperty>();
internal CFStream cfStream;

/*
Expand Down
2 changes: 1 addition & 1 deletion sources/OpenMcdf.Extensions/OLEProperties/OLEProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OpenMcdf.Extensions.OLEProperties
{
public class OLEProperty
{
private OLEPropertiesContainer container;
private readonly OLEPropertiesContainer container;

internal OLEProperty(OLEPropertiesContainer container)
{
Expand Down
7 changes: 3 additions & 4 deletions sources/OpenMcdf.Extensions/OLEProperties/PropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ static PropertyFactory()

public ITypedPropertyValue NewProperty(VTPropertyType vType, int codePage, uint propertyIdentifier, bool isVariant = false)
{
ITypedPropertyValue pr = null;

ITypedPropertyValue pr;
switch ((VTPropertyType)((ushort)vType & 0x00FF))
{
case VTPropertyType.VT_I1:
Expand Down Expand Up @@ -382,7 +381,7 @@ public override void WriteScalarValue(System.IO.BinaryWriter bw, DateTime pValue
protected class VT_LPSTR_Property : TypedPropertyValue<string>
{
private byte[] data;
private int codePage;
private readonly int codePage;

public VT_LPSTR_Property(VTPropertyType vType, int codePage, bool isVariant) : base(vType, isVariant)
{
Expand Down Expand Up @@ -482,7 +481,7 @@ public VT_Unaligned_LPSTR_Property(VTPropertyType vType, int codePage, bool isVa
private class VT_LPWSTR_Property : TypedPropertyValue<string>
{
private byte[] data;
private int codePage;
private readonly int codePage;

public VT_LPWSTR_Property(VTPropertyType vType, int codePage, bool isVariant) : base(vType, isVariant)
{
Expand Down
22 changes: 2 additions & 20 deletions sources/OpenMcdf.Extensions/OLEProperties/PropertySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,9 @@ public PropertyContext PropertyContext

public uint NumProperties { get; set; }

List<PropertyIdentifierAndOffset> propertyIdentifierAndOffsets
= new List<PropertyIdentifierAndOffset>();
public List<PropertyIdentifierAndOffset> PropertyIdentifierAndOffsets { get; set; } = new List<PropertyIdentifierAndOffset>();

public List<PropertyIdentifierAndOffset> PropertyIdentifierAndOffsets
{
get { return propertyIdentifierAndOffsets; }
set { propertyIdentifierAndOffsets = value; }
}

List<IProperty> properties = new List<IProperty>();
public List<IProperty> Properties
{
get
{
return properties;
}
set
{
properties = value;
}
}
public List<IProperty> Properties { get; set; } = new List<IProperty>();

public void LoadContext(int propertySetOffset, BinaryReader br)
{
Expand Down
18 changes: 7 additions & 11 deletions sources/OpenMcdf.Extensions/OLEProperties/TypedPropertyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace OpenMcdf.Extensions.OLEProperties
{
internal abstract class TypedPropertyValue<T> : ITypedPropertyValue
{
private bool isVariant = false;
private PropertyDimensions dim = PropertyDimensions.IsScalar;

private VTPropertyType _VTType;
private readonly VTPropertyType _VTType;

public PropertyType PropertyType => PropertyType.TypedPropertyValue;

Expand All @@ -20,13 +17,13 @@ internal abstract class TypedPropertyValue<T> : ITypedPropertyValue
public TypedPropertyValue(VTPropertyType vtType, bool isVariant = false)
{
this._VTType = vtType;
dim = CheckPropertyDimensions(vtType);
this.isVariant = isVariant;
PropertyDimensions = CheckPropertyDimensions(vtType);
this.IsVariant = isVariant;
}

public PropertyDimensions PropertyDimensions => dim;
public PropertyDimensions PropertyDimensions { get; } = PropertyDimensions.IsScalar;

public bool IsVariant => isVariant;
public bool IsVariant { get; } = false;

protected virtual bool NeedsPadding { get; set; } = true;

Expand Down Expand Up @@ -113,9 +110,8 @@ public void Read(System.IO.BinaryReader br)
public void Write(BinaryWriter bw)
{
long currentPos = bw.BaseStream.Position;
int size = 0;
int m = 0;

int size;
int m;
switch (this.PropertyDimensions)
{
case PropertyDimensions.IsScalar:
Expand Down
2 changes: 1 addition & 1 deletion sources/OpenMcdf.Extensions/StreamDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenMcdf.Extensions
/// </summary>
public class StreamDecorator : Stream
{
private CFStream cfStream;
private readonly CFStream cfStream;
private long position = 0;

/// <summary>
Expand Down
55 changes: 24 additions & 31 deletions sources/OpenMcdf/CFItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ namespace OpenMcdf
/// </example>
public abstract class CFItem : IComparable<CFItem>
{
private CompoundFile compoundFile;

protected CompoundFile CompoundFile => compoundFile;
protected CompoundFile CompoundFile { get; }

protected void CheckDisposed()
{
if (compoundFile.IsClosed)
if (CompoundFile.IsClosed)
throw new CFDisposedException("Owner Compound file has been closed and owned items have been invalidated");
}

Expand All @@ -53,22 +51,17 @@ protected CFItem()

protected CFItem(CompoundFile compoundFile)
{
this.compoundFile = compoundFile;
this.CompoundFile = compoundFile;
}

#region IDirectoryEntry Members

private IDirectoryEntry dirEntry;

internal IDirectoryEntry DirEntry
{
get { return dirEntry; }
set { dirEntry = value; }
}
internal IDirectoryEntry DirEntry { get; set; }

internal int CompareTo(CFItem other)
{
return this.dirEntry.CompareTo(other.DirEntry);
return this.DirEntry.CompareTo(other.DirEntry);
}

#endregion
Expand All @@ -77,7 +70,7 @@ internal int CompareTo(CFItem other)

public int CompareTo(object obj)
{
return this.dirEntry.CompareTo(((CFItem)obj).DirEntry);
return this.DirEntry.CompareTo(((CFItem)obj).DirEntry);
}

#endregion
Expand Down Expand Up @@ -112,7 +105,7 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return this.dirEntry.GetEntryName().GetHashCode();
return this.DirEntry.GetEntryName().GetHashCode();
}

/// <summary>
Expand All @@ -122,7 +115,7 @@ public string Name
{
get
{
string n = this.dirEntry.GetEntryName();
string n = this.DirEntry.GetEntryName();
if (n != null && n.Length > 0)
{
return n.TrimEnd('\0');
Expand All @@ -136,7 +129,7 @@ public string Name
/// Size in bytes of the item. It has a valid value
/// only if entity is a stream, otherwise it is set to zero.
/// </summary>
public long Size => this.dirEntry.Size;
public long Size => this.DirEntry.Size;

/// <summary>
/// Return true if item is Storage
Expand All @@ -145,7 +138,7 @@ public string Name
/// This check doesn't use reflection or runtime type information
/// and doesn't suffer related performance penalties.
/// </remarks>
public bool IsStorage => this.dirEntry.StgType == StgType.StgStorage;
public bool IsStorage => this.DirEntry.StgType == StgType.StgStorage;

/// <summary>
/// Return true if item is a Stream
Expand All @@ -154,7 +147,7 @@ public string Name
/// This check doesn't use reflection or runtime type information
/// and doesn't suffer related performance penalties.
/// </remarks>
public bool IsStream => this.dirEntry.StgType == StgType.StgStream;
public bool IsStream => this.DirEntry.StgType == StgType.StgStream;

/// <summary>
/// Return true if item is the Root Storage
Expand All @@ -163,7 +156,7 @@ public string Name
/// This check doesn't use reflection or runtime type information
/// and doesn't suffer related performance penalties.
/// </remarks>
public bool IsRoot => this.dirEntry.StgType == StgType.StgRoot;
public bool IsRoot => this.DirEntry.StgType == StgType.StgRoot;

/// <summary>
/// Get/Set the Creation Date of the current item
Expand All @@ -172,13 +165,13 @@ public DateTime CreationDate
{
get
{
return DateTime.FromFileTime(BitConverter.ToInt64(this.dirEntry.CreationDate, 0));
return DateTime.FromFileTime(BitConverter.ToInt64(this.DirEntry.CreationDate, 0));
}

set
{
if (this.dirEntry.StgType != StgType.StgStream && this.dirEntry.StgType != StgType.StgRoot)
this.dirEntry.CreationDate = BitConverter.GetBytes(value.ToFileTime());
if (this.DirEntry.StgType != StgType.StgStream && this.DirEntry.StgType != StgType.StgRoot)
this.DirEntry.CreationDate = BitConverter.GetBytes(value.ToFileTime());
else
throw new CFException("Creation Date can only be set on storage entries");
}
Expand All @@ -191,13 +184,13 @@ public DateTime ModifyDate
{
get
{
return DateTime.FromFileTime(BitConverter.ToInt64(this.dirEntry.ModifyDate, 0));
return DateTime.FromFileTime(BitConverter.ToInt64(this.DirEntry.ModifyDate, 0));
}

set
{
if (this.dirEntry.StgType != StgType.StgStream && this.dirEntry.StgType != StgType.StgRoot)
this.dirEntry.ModifyDate = BitConverter.GetBytes(value.ToFileTime());
if (this.DirEntry.StgType != StgType.StgStream && this.DirEntry.StgType != StgType.StgRoot)
this.DirEntry.ModifyDate = BitConverter.GetBytes(value.ToFileTime());
else
throw new CFException("Modify Date can only be set on storage entries");
}
Expand All @@ -210,13 +203,13 @@ public Guid CLSID
{
get
{
return this.dirEntry.StorageCLSID;
return this.DirEntry.StorageCLSID;
}
set
{
if (this.dirEntry.StgType != StgType.StgStream)
if (this.DirEntry.StgType != StgType.StgStream)
{
this.dirEntry.StorageCLSID = value;
this.DirEntry.StorageCLSID = value;
}
else
throw new CFException("Object class GUID can only be set on Root and Storage entries");
Expand All @@ -225,13 +218,13 @@ public Guid CLSID

int IComparable<CFItem>.CompareTo(CFItem other)
{
return this.dirEntry.CompareTo(other.DirEntry);
return this.DirEntry.CompareTo(other.DirEntry);
}

public override string ToString()
{
if (this.dirEntry != null)
return "[" + this.dirEntry.LeftSibling + "," + this.dirEntry.SID + "," + this.dirEntry.RightSibling + "]" + " " + this.dirEntry.GetEntryName();
if (this.DirEntry != null)
return "[" + this.DirEntry.LeftSibling + "," + this.DirEntry.SID + "," + this.DirEntry.RightSibling + "]" + " " + this.DirEntry.GetEntryName();
else
return string.Empty;
}
Expand Down
3 changes: 1 addition & 2 deletions sources/OpenMcdf/CFStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ IDirectoryEntry cfo
catch (RBTreeDuplicatedItemException)
{
CompoundFile.ResetDirectoryEntry(cfo.SID);
cfo = null;
throw new CFDuplicatedItemException("An entry with name '" + storageName + "' is already present in storage '" + this.Name + "' ");
}

Expand Down Expand Up @@ -547,7 +546,7 @@ public void Delete(string entryName)
if (((IDirectoryEntry)foundObj).StgType == StgType.StgRoot)
throw new CFException("Root storage cannot be removed");

IRBNode altDel = null;
IRBNode altDel;
switch (((IDirectoryEntry)foundObj).StgType)
{
case StgType.StgStorage:
Expand Down
Loading

0 comments on commit b95add4

Please sign in to comment.