Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert project to PCL #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ $RECYCLE.BIN/
build/1.*
build/nuspec/FileFormatWavefront/lib
build/nuspec/FileFormatWavefront/lib/
/source/packages
20 changes: 20 additions & 0 deletions source/FileFormatWavefront/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace FileFormatWavefront.Extensions
{
internal static class ListExtensions
{
/// <summary>
/// Returns a read-only IList&lt;T&gt; wrapper for the current collection.
/// </summary>
/// <returns>A ReadOnlyCollection&lt;T&gt; that acts as a read-only
/// wrapper around the current IList&lt;T&gt;.
/// </returns>
public static ReadOnlyCollection<T> AsReadOnly<T>(this List<T> list)
{
return new ReadOnlyCollection<T>(list);
}
}
}
2 changes: 1 addition & 1 deletion source/FileFormatWavefront/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class StringExtensions
/// <returns>True if the string matches the linetype.</returns>
public static bool IsLineType(this string @this, string lineType)
{
return string.Equals(@this, lineType, StringComparison.InvariantCultureIgnoreCase);
return string.Equals(@this, lineType, StringComparison.OrdinalIgnoreCase);
}
}
}
22 changes: 17 additions & 5 deletions source/FileFormatWavefront/FileFormatMtl.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using FileFormatWavefront.Extensions;
using FileFormatWavefront.Internals;
using FileFormatWavefront.Model;
using PCLStorage;
using Splat;

namespace FileFormatWavefront
{
Expand All @@ -23,10 +24,18 @@ public static class FileFormatMtl
/// <returns>The results of the file load.</returns>
public static FileLoadResult<List<Material>> Load(string path, bool loadTextureImages)
{
var file = FileSystem.Current.GetFileFromPathAsync(path).Result;

if (file == null) throw new FileNotFoundException("File not found", path);

// Create a streamreader and read the data.
using(var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var streamReader = new StreamReader(stream))
return Read(streamReader, path, loadTextureImages);
using (var stream = file.OpenAsync(FileAccess.Read).Result)
{
using(var streamReader = new StreamReader(stream))
{
return Read(streamReader, path, loadTextureImages);
}
}
}

/// <summary>
Expand Down Expand Up @@ -180,7 +189,10 @@ private static TextureMap ReadTextureMap(string fileName, int lineNumber, List<M
try
{
var path = Path.Combine(Path.GetDirectoryName(fileName), textureFileName);
textureMap.Image = Image.FromFile(path);
var file = FileSystem.Current.GetFileFromPathAsync(path).Result;

using (var stream = file.OpenAsync(FileAccess.Read).Result)
textureMap.Image = BitmapLoader.Current.Load(stream, null /*original width*/, null /*original height*/).Result;
}
catch (Exception exception)
{
Expand Down
14 changes: 9 additions & 5 deletions source/FileFormatWavefront/FileFormatObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FileFormatWavefront.Extensions;
using FileFormatWavefront.Internals;
using FileFormatWavefront.Model;
using PCLStorage;

namespace FileFormatWavefront
{
Expand All @@ -24,13 +25,16 @@ public static class FileFormatObj
/// </returns>
public static FileLoadResult<Scene> Load(string path, bool loadTextureImages)
{
// Create a stream reader.
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
var file = FileSystem.Current.GetFileFromPathAsync(path).Result;

if (file == null) throw new FileNotFoundException("File not found", path);

// Create a streamreader and read the data.
using (var stream = file.OpenAsync(FileAccess.Read).Result)
{
using (var reader = new StreamReader(stream))
using (var streamReader = new StreamReader(stream))
{
// Read the scene.
return ReadScene(reader, path, loadTextureImages);
return ReadScene(streamReader, path, loadTextureImages);
}
}
}
Expand Down
29 changes: 20 additions & 9 deletions source/FileFormatWavefront/FileFormatWavefront.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<AssemblyName>FileFormatWavefront</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -31,16 +34,21 @@
<DocumentationFile>bin\Release\FileFormatWavefront.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="PCLStorage, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLStorage.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\ListExtensions.cs" />
<Compile Include="FileFormatObj.cs" />
<Compile Include="FileFormatMtl.cs" />
<Compile Include="FileLoadResult.cs" />
Expand All @@ -59,7 +67,10 @@
<Compile Include="Model\Vertex.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
1 change: 1 addition & 0 deletions source/FileFormatWavefront/FileLoadResult.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FileFormatWavefront.Extensions;
using System.Collections.Generic;
using System.Collections.ObjectModel;

Expand Down
1 change: 1 addition & 0 deletions source/FileFormatWavefront/Model/Face.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FileFormatWavefront.Extensions;
using System.Collections.Generic;
using System.Collections.ObjectModel;

Expand Down
3 changes: 2 additions & 1 deletion source/FileFormatWavefront/Model/Group.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FileFormatWavefront.Extensions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down
3 changes: 2 additions & 1 deletion source/FileFormatWavefront/Model/Scene.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FileFormatWavefront.Extensions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down
3 changes: 2 additions & 1 deletion source/FileFormatWavefront/Model/TextureMap.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Splat;
using System.Drawing;

namespace FileFormatWavefront.Model
Expand All @@ -16,6 +17,6 @@ public class TextureMap
/// Gets the texture image.
/// Note that this is only set if the file is loaded with the 'loadTextureImages' option set to <c>true</c>.
/// </summary>
public Image Image { get; internal set; }
public IBitmap Image { get; internal set; }
}
}
5 changes: 5 additions & 0 deletions source/FileFormatWavefront/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="PCLStorage" version="1.0.2" targetFramework="portable45-net45+win8+wpa81" />
<package id="Splat" version="1.6.2" targetFramework="portable45-net45+win8+wpa81" />
</packages>