Skip to content

Commit

Permalink
Adding minor improvements
Browse files Browse the repository at this point in the history
 - Fixed a bug where importedFrom attribute is not an actual path
 - Added sorting to certain lists so that repeated conversions do not result in unnecessarry differences
 - Improved readme
  • Loading branch information
waqasilyas committed Jan 6, 2018
1 parent 3d29345 commit 6f440a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
12 changes: 8 additions & 4 deletions BmprArchiveModel/Model/BmprArchiveReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public static MockupProject LoadProject(String sourceFile, bool createHashes)
// Load thumbnails
InternalLoadThumbnails(db, project, createHashes);
}

// Sort members so that serialization always produces similar results
project.Mockups = project.Mockups.OrderBy(n => n.Attributes.Name).ToList();
project.SymbolLibraries = project.SymbolLibraries.OrderBy(n => n.Attributes.Name).ToList();
project.Assets = project.Assets.OrderBy(i => i.Attributes.Name).ToList();
project.Branches = project.Branches.OrderBy(i => i.Id).ToList();

return project;
}
Expand Down Expand Up @@ -141,8 +147,6 @@ private static ProjectInfo InternalLoadProjectInfo(DatabaseAccess db)

private static void InternalLoadResources(DatabaseAccess db, MockupProject project, bool createHashes)
{
List<Mockup> mockups = new List<Mockup>();

String[][] data = db.GetTableContent(BarTable.RESOURCES.ToString());
foreach (String[] row in data)
{
Expand Down Expand Up @@ -194,9 +198,9 @@ private static void InternalLoadResources(DatabaseAccess db, MockupProject proje
if (control != null)
{
if (attributes.Kind == ResourceKind.Mockup)
(container as Mockup).Controls = control.ToObject<MockupControl[]>();
(container as Mockup).Controls = control.ToObject<MockupControl[]>().OrderBy(i => i.ID).ToArray();
else
(container as SymbolLibrary).Symbols = control.ToObject<MockupSymbol[]>();
(container as SymbolLibrary).Symbols = control.ToObject<MockupSymbol[]>().OrderBy(i => i.ID).ToArray();
}
else if (!attributes.Trashed)
{
Expand Down
10 changes: 5 additions & 5 deletions BmprArchiveModel/Model/MockupProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public class MockupProject
#region Properties

public ProjectInfo Info { get; set; }
public List<Mockup> Mockups { get; } = new List<Mockup>();
public List<SymbolLibrary> SymbolLibraries { get; } = new List<SymbolLibrary>();
public List<ProjectAsset> Assets { get; } = new List<ProjectAsset>();
public List<BranchInfo> Branches { get; } = new List<BranchInfo>();
public List<ResourceThumbnail> Thumbnails { get; } = new List<ResourceThumbnail>();
public List<Mockup> Mockups { get; set; } = new List<Mockup>();
public List<SymbolLibrary> SymbolLibraries { get; set; } = new List<SymbolLibrary>();
public List<ProjectAsset> Assets { get; set; } = new List<ProjectAsset>();
public List<BranchInfo> Branches { get; set; } = new List<BranchInfo>();
public List<ResourceThumbnail> Thumbnails { get; set; } = new List<ResourceThumbnail>();
#endregion
}
}
8 changes: 3 additions & 5 deletions BmprArchiveModel/Model/Properties/ResourceAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ protected override void initializeAttributes(JObject attributes)
// Mime type of the resource
MimeType = (String)attributes[MIME_ATTRIB];

String path = (String)attributes[IMPORTED_ATTRIB];
if (path != null && path.Length > 0)
ImportedFrom = new Uri(path);

ImportedFrom = (String)attributes[IMPORTED_ATTRIB];

// Remove all known attributes
attributes.Remove(KIND_ATTRIB);
attributes.Remove(TRASHED_ATTRIB);
Expand Down Expand Up @@ -99,7 +97,7 @@ protected override void initializeAttributes(JObject attributes)
public String MimeType { get; set; }

[JsonProperty(Order = 13)]
public Uri ImportedFrom { get; set; }
public String ImportedFrom { get; set; }

#endregion
}
Expand Down
14 changes: 10 additions & 4 deletions JsonConverterBmpr/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Program

static void Main(string[] args)
{
int errorCode = 0;

// Parameters
String source = null;
String target = null;
Expand All @@ -40,7 +42,7 @@ static void Main(string[] args)
{
forceOverwrite = true;
}
else if (a.Equals("-nh"))
else if (a.Equals("-n"))
{
createHashes = false;
}
Expand All @@ -66,13 +68,15 @@ static void Main(string[] args)
if (source == null)
{
PrintHelp();
Environment.Exit(ErrorBadArguments);
errorCode = ErrorBadArguments;
return;
}

if (!File.Exists(source))
{
PrintError("Input file '" + source + "' does not exist");
Environment.Exit(ErrorFileDoesntExists);
errorCode = ErrorFileDoesntExists;
return;
}

// Load project file
Expand Down Expand Up @@ -121,6 +125,8 @@ static void Main(string[] args)
Console.In.Read();
#endif
}

Environment.Exit(errorCode);
}

static void PrintHeader()
Expand All @@ -139,7 +145,7 @@ SOURCE A *.bmpr file to convert
TARGET The destination file to save the JSON output. If not give, the
JSON is emitted on standard output
-f Force overwrite if TARGET exists
-nh Do not replace binary data with hashes. By default a data hash
-n Do not replace binary data with hashes. By default a data hash
is calculated and emitted for binary data like images
-h Prints this description");
}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In this regard the main objectives are:
* Focus exclusively on readability
* Try to match UI concepts and workflow while structuring the JSON, as compared to representing the underlying RDBMS organization
* Try to order properties to increase readability, like having ID, name, type kind of properties at the top under an object
* Friendly to diff tools, don't rely on a lot of command line options
* Friendly to diff tools, don't rely on a lot of command line options. And don't ask for user inputs

# Usage
```
Expand All @@ -23,10 +23,11 @@ Usage:
TARGET The destination file to save the JSON output. If not give, the
JSON is emitted on standard output
-f Force overwrite if TARGET exists
-nh Do not replace binary data with hashes. By default a data hash
-n Do not replace binary data with hashes. By default a data hash
is calculated and emitted for binary data like images
-h Prints this description
```
Note: Requires .NET Framework 4.5

# TODO
* Simplify the awkward mockup.controls.control.children.controls.control hierarchy
Expand Down

0 comments on commit 6f440a0

Please sign in to comment.