Skip to content

Commit

Permalink
Reformat everything, and put in a fix for #7
Browse files Browse the repository at this point in the history
  • Loading branch information
chelh committed Mar 14, 2017
1 parent 7685c60 commit beebd69
Show file tree
Hide file tree
Showing 24 changed files with 1,081 additions and 537 deletions.
21 changes: 14 additions & 7 deletions src/VBASync.Model/AppIniFile.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using System.IO.IsolatedStorage;
using System.Text;

namespace VBASync.Model {
public class AppIniFile : IniFile {
namespace VBASync.Model
{
public class AppIniFile : IniFile
{
public AppIniFile(IsolatedStorageFile store, string fileName, Encoding encoding = null)
: base(store, fileName, encoding) {
: base(store, fileName, encoding)
{
}

public AppIniFile(string filePath, Encoding encoding = null) : base(filePath, encoding) {
public AppIniFile(string filePath, Encoding encoding = null) : base(filePath, encoding)
{
}

public ActionType? GetActionType(string subject, string key) {
if (Dict.TryGetValue($"{subject}\0{key}", out var s)) {
switch (s.ToUpperInvariant()) {
public ActionType? GetActionType(string subject, string key)
{
if (Dict.TryGetValue($"{subject}\0{key}", out var s))
{
switch (s.ToUpperInvariant())
{
case "EXTRACT":
return ActionType.Extract;
case "PUBLISH":
Expand Down
197 changes: 135 additions & 62 deletions src/VBASync.Model/DiffPlex_ModVba.cs

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/VBASync.Model/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;

namespace VBASync.Model {
internal static class Extensions {
public static byte[] Range(this byte[] src, uint start, uint size) {
namespace VBASync.Model
{
internal static class Extensions
{
public static byte[] Range(this byte[] src, uint start, uint size)
{
var ret = new byte[size];
if (size > 0) {
if (size > 0)
{
Array.Copy(src, start, ret, 0, size);
}
return ret;
Expand Down
63 changes: 42 additions & 21 deletions src/VBASync.Model/FrxObjects/CommandButtonControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
using System.IO;
using System.Linq;

namespace VBASync.Model.FrxObjects {
internal class CommandButtonControl {
public CommandButtonControl(byte[] b) {
namespace VBASync.Model.FrxObjects
{
internal class CommandButtonControl
{
public CommandButtonControl(byte[] b)
{
using (var st = new MemoryStream(b))
using (var r = new FrxReader(st)) {
using (var r = new FrxReader(st))
{
MinorVersion = r.ReadByte();
MajorVersion = r.ReadByte();

Expand All @@ -29,7 +33,8 @@ public CommandButtonControl(byte[] b) {
Size = PropMask.HasSize ? r.ReadCoords() : Tuple.Create(0, 0);

r.AlignTo(4);
if (cbCommandButton != r.BaseStream.Position - 4) {
if (cbCommandButton != r.BaseStream.Position - 4)
{
throw new ApplicationException("Error reading 'o' stream in .frx data: expected cbCommandButton size "
+ $"{r.BaseStream.Position - 4}, but actual size was {cbCommandButton}.");
}
Expand Down Expand Up @@ -57,21 +62,27 @@ public CommandButtonControl(byte[] b) {
public TextProps TextProps { get; }
public uint VariousPropertyBits { get; }

public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj)) {
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType()) {
if (obj.GetType() != GetType())
{
return false;
}
return Equals((CommandButtonControl)obj);
}

public override int GetHashCode() {
unchecked {
public override int GetHashCode()
{
unchecked
{
var hashCode = Picture?.Length.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (MouseIcon?.Length.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (TextProps?.GetHashCode() ?? 0);
Expand All @@ -90,7 +101,8 @@ public override int GetHashCode() {
}
}

protected bool Equals(CommandButtonControl other) {
protected bool Equals(CommandButtonControl other)
{
return Picture.SequenceEqual(other.Picture) && MouseIcon.SequenceEqual(other.MouseIcon) && MinorVersion == other.MinorVersion
&& MajorVersion == other.MajorVersion && Equals(PropMask, other.PropMask) && Equals(ForeColor, other.ForeColor)
&& Equals(BackColor, other.BackColor) && VariousPropertyBits == other.VariousPropertyBits && string.Equals(Caption, other.Caption)
Expand All @@ -99,8 +111,10 @@ protected bool Equals(CommandButtonControl other) {
}
}

internal class CommandButtonPropMask {
public CommandButtonPropMask(uint i) {
internal class CommandButtonPropMask
{
public CommandButtonPropMask(uint i)
{
Func<int, bool> bit = j => (i & ((uint)1 << j)) != 0;
HasForeColor = bit(0);
HasBackColor = bit(1);
Expand All @@ -127,21 +141,27 @@ public CommandButtonPropMask(uint i) {
public bool HasVariousPropertyBits { get; }
public bool TakeFocusOnClick { get; }

public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj)) {
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType()) {
if (obj.GetType() != GetType())
{
return false;
}
return Equals((CommandButtonPropMask)obj);
}

public override int GetHashCode() {
unchecked {
public override int GetHashCode()
{
unchecked
{
var hashCode = HasForeColor.GetHashCode();
hashCode = (hashCode * 397) ^ HasBackColor.GetHashCode();
hashCode = (hashCode * 397) ^ HasVariousPropertyBits.GetHashCode();
Expand All @@ -157,7 +177,8 @@ public override int GetHashCode() {
}
}

protected bool Equals(CommandButtonPropMask other) {
protected bool Equals(CommandButtonPropMask other)
{
return HasForeColor == other.HasForeColor && HasBackColor == other.HasBackColor && HasVariousPropertyBits == other.HasVariousPropertyBits
&& HasCaption == other.HasCaption && HasPicturePosition == other.HasPicturePosition && HasSize == other.HasSize
&& HasMousePointer == other.HasMousePointer && HasPicture == other.HasPicture && HasAccelerator == other.HasAccelerator
Expand Down
Loading

0 comments on commit beebd69

Please sign in to comment.