Permalink
Browse files

Merge branch 'develop3d' of https://github.com/mono/MonoGame into dev…

…elop3d

Conflicts:
	MonoGame.Framework/Storage/StorageDevice.cs
  • Loading branch information...
2 parents 19f1a9d + 58a37cd commit c0dd813f373eee4fb8ce758db8c3b712103160a5 Alexandre Zollinger Chohfi committed Feb 18, 2013
@@ -269,7 +269,7 @@ internal DisplayOrientation GetEffectiveSupportedOrientations()
}
else
{
- return DisplayOrientation.Portrait | DisplayOrientation.PortraitUpsideDown;
+ return DisplayOrientation.Portrait | DisplayOrientation.PortraitDown;
}
}
else
@@ -294,8 +294,8 @@ internal void SetOrientation(DisplayOrientation newOrientation, bool applyGraphi
newOrientation = DisplayOrientation.LandscapeRight;
else if ((supported & DisplayOrientation.Portrait) != 0)
newOrientation = DisplayOrientation.Portrait;
- else if ((supported & DisplayOrientation.PortraitUpsideDown) != 0)
- newOrientation = DisplayOrientation.PortraitUpsideDown;
+ else if ((supported & DisplayOrientation.PortraitDown) != 0)
+ newOrientation = DisplayOrientation.PortraitDown;
}
DisplayOrientation oldOrientation = CurrentOrientation;
@@ -386,7 +386,7 @@ private set
{
DisplayOrientation supported = GetEffectiveSupportedOrientations();
ScreenOrientation requestedOrientation = ScreenOrientation.Unspecified;
- bool wasPortrait = _currentOrientation == DisplayOrientation.Portrait || _currentOrientation == DisplayOrientation.PortraitUpsideDown;
+ bool wasPortrait = _currentOrientation == DisplayOrientation.Portrait || _currentOrientation == DisplayOrientation.PortraitDown;
bool requestPortrait = false;
bool didOrientationChange = false;
@@ -413,7 +413,7 @@ private set
requestedOrientation = (ScreenOrientation)ScreenOrientationAll.Portrait;
requestPortrait = true;
break;
- case DisplayOrientation.PortraitUpsideDown:
+ case DisplayOrientation.PortraitDown:
requestedOrientation = (ScreenOrientation)ScreenOrientationAll.ReversePortrait;
requestPortrait = true;
break;
@@ -432,8 +432,8 @@ private set
requestPortrait = false;
}
// Check if the requested orientation is either of the portrain orientations and any portrait orientation is supported.
- else if ((value == DisplayOrientation.Portrait || value == DisplayOrientation.PortraitUpsideDown) &&
- ((supported & (DisplayOrientation.Portrait | DisplayOrientation.PortraitUpsideDown)) != 0))
+ else if ((value == DisplayOrientation.Portrait || value == DisplayOrientation.PortraitDown) &&
+ ((supported & (DisplayOrientation.Portrait | DisplayOrientation.PortraitDown)) != 0))
{
didOrientationChange = true;
_currentOrientation = DisplayOrientation.Portrait;
@@ -55,7 +55,7 @@ public override void OnOrientationChanged(int orientation)
break;
case 0: disporientation = DisplayOrientation.Portrait;
break;
- case 180: disporientation = DisplayOrientation.PortraitUpsideDown;
+ case 180: disporientation = DisplayOrientation.PortraitDown;
break;
default:
disporientation = DisplayOrientation.LandscapeLeft;
@@ -25,7 +25,11 @@ public static ConstructorInfo GetDefaultConstructor(this Type type)
public static PropertyInfo[] GetAllProperties(this Type type)
{
#if WINRT
- return type.GetTypeInfo().DeclaredProperties.ToArray();
+ PropertyInfo[] infos= type.GetTypeInfo().DeclaredProperties.ToArray();
+ var nonStaticPropertyInfos = from p in infos
+ where (p.GetMethod != null) && (!p.GetMethod.IsStatic)
+ select p;
+ return nonStaticPropertyInfos.ToArray();
#else
var attrs = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
return type.GetProperties(attrs);
@@ -36,7 +40,11 @@ public static PropertyInfo[] GetAllProperties(this Type type)
public static FieldInfo[] GetAllFields(this Type type)
{
#if WINRT
- return type.GetTypeInfo().DeclaredFields.ToArray();
+ FieldInfo[] fields= type.GetTypeInfo().DeclaredFields.ToArray();
+ var nonStaticFields = from field in fields
+ where !field.IsStatic
+ select field;
+ return nonStaticFields.ToArray();
#else
var attrs = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
return type.GetFields(attrs);
@@ -42,24 +42,15 @@ 1. Definitions
namespace Microsoft.Xna.Framework
{
- [Flags]
- public enum DisplayOrientation
- {
- /// <summary>
- /// In Xna, this value is Default = 0. The effect of setting
- /// GraphicsDeviceManager.SupportedOrientations = Default is the same as setting
- /// GraphicsDeviceManager.SupportedOrientations = LandscapeLeft | LandscapeRight.
- /// </summary>
- Default = 1,
- LandscapeLeft = 2,
- LandscapeRight = 4,
- Portrait = 8,
- // iPhone specific Orientations
- FaceDown = 16,
- FaceUp = 32,
- // Android can also use this orientation
- PortraitUpsideDown = 64,
- Unknown = 128,
- }
+ [Flags]
+ public enum DisplayOrientation
+ {
+ Default = 0,
+ LandscapeLeft = 1,
+ LandscapeRight = 2,
+ Portrait = 4,
+ PortraitDown = 8,
+ Unknown = 16
+ }
}
@@ -284,7 +284,7 @@ private void FillTouchCollection(NSSet touches)
break;
}
- case DisplayOrientation.PortraitUpsideDown :
+ case DisplayOrientation.PortraitDown :
{
translatedPosition = new Vector2( ClientBounds.Width - position.X, ClientBounds.Height - position.Y );
break;
@@ -316,7 +316,7 @@ private void FillTouchCollection(NSSet touches)
break;
}
- case DisplayOrientation.PortraitUpsideDown :
+ case DisplayOrientation.PortraitDown :
{
translatedPosition = new Vector2( ClientBounds.Width - position.X, ClientBounds.Height - position.Y );
break;
@@ -118,9 +118,13 @@ internal StorageContainer(StorageDevice device, string name, PlayerIndex? player
_playerIndex = playerIndex;
// From the examples the root is based on MyDocuments folder
+#if WINDOWS_STOREAPP
+ var saved = "";
+#else
var root = StorageDevice.StorageRoot;
var saved = Path.Combine(root,"SavedGames");
- _storagePath = Path.Combine(saved,name);
+#endif
+ _storagePath = Path.Combine(saved, name);
var playerSave = string.Empty;
if (playerIndex.HasValue) {
@@ -133,7 +137,8 @@ internal StorageContainer(StorageDevice device, string name, PlayerIndex? player
// Create the "device" if need be
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- folder.CreateFolderAsync(_storagePath, CreationCollisionOption.OpenIfExists).GetResults();
+ var task = folder.CreateFolderAsync(_storagePath, CreationCollisionOption.OpenIfExists);
+ task.AsTask().Wait();
#else
if (!Directory.Exists(_storagePath))
Directory.CreateDirectory(_storagePath);
@@ -182,7 +187,8 @@ public void CreateDirectory (string directory)
// Now let's try to create it
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- folder.CreateFolderAsync(dirPath, CreationCollisionOption.OpenIfExists).GetResults();
+ var task = folder.CreateFolderAsync(dirPath, CreationCollisionOption.OpenIfExists);
+ task.AsTask().Wait();
#else
Directory.CreateDirectory(dirPath);
#endif
@@ -226,8 +232,8 @@ public void DeleteDirectory (string directory)
// Now let's try to delete itd
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- var deleteFolder = folder.GetFolderAsync(dirPath).GetResults();
- deleteFolder.DeleteAsync().GetResults();
+ var deleteFolder = folder.GetFolderAsync(dirPath).AsTask().GetAwaiter().GetResult();
+ deleteFolder.DeleteAsync().AsTask().Wait();
#else
Directory.Delete(dirPath);
#endif
@@ -247,8 +253,8 @@ public void DeleteFile (string file)
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- var deleteFile = folder.GetFileAsync(filePath).GetResults();
- deleteFile.DeleteAsync().GetResults();
+ var deleteFile = folder.GetFileAsync(filePath).AsTask().GetAwaiter().GetResult();
+ deleteFile.DeleteAsync().AsTask().Wait();
#else
// Now let's try to delete it
File.Delete(filePath);
@@ -271,9 +277,17 @@ public bool DirectoryExists (string directory)
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- var result = folder.GetFolderAsync(dirPath).GetResults();
+
+ try
+ {
+ var result = folder.GetFolderAsync(dirPath).GetResults();
return result != null;
-#else
+ }
+ catch
+ {
+ return false;
+ }
+#else
return Directory.Exists(dirPath);
#endif
}
@@ -303,8 +317,16 @@ public bool FileExists (string file)
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- var existsFile = folder.GetFileAsync(filePath).GetResults();
- return existsFile != null;
+ // GetFile returns an exception if the file doesn't exist, so we catch it here and return the boolean.
+ try
+ {
+ var existsFile = folder.GetFileAsync(filePath).GetAwaiter().GetResult();
+ return existsFile != null;
+ }
+ catch
+ {
+ return false;
+ }
#else
// return A new file with read/write access.
return File.Exists(filePath);
@@ -319,7 +341,7 @@ public string[] GetDirectoryNames ()
{
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- var results = folder.GetFoldersAsync().GetResults();
+ var results = folder.GetFoldersAsync().AsTask().GetAwaiter().GetResult();
return results.Select<StorageFolder, string>(e => e.Name).ToArray();
#else
return Directory.GetDirectories(_storagePath);
@@ -344,7 +366,7 @@ public string[] GetFileNames ()
{
#if WINDOWS_STOREAPP
var folder = ApplicationData.Current.LocalFolder;
- var results = folder.GetFilesAsync().GetResults();
+ var results = folder.GetFilesAsync().AsTask().GetAwaiter().GetResult();
return results.Select<StorageFile, string>(e => e.Name).ToArray();
#else
return Directory.GetFiles(_storagePath);
@@ -365,7 +387,7 @@ public string[] GetFileNames (string searchPattern)
var folder = ApplicationData.Current.LocalFolder;
var options = new QueryOptions( CommonFileQuery.DefaultQuery, new [] { searchPattern } );
var query = folder.CreateFileQueryWithOptions(options);
- var files = query.GetFilesAsync().GetResults();
+ var files = query.GetFilesAsync().AsTask().GetAwaiter().GetResult();
return files.Select<StorageFile, string>(e => e.Name).ToArray();
#else
return Directory.GetFiles(_storagePath, searchPattern);
@@ -420,10 +442,14 @@ public Stream OpenFile (string file, FileMode fileMode, FileAccess fileAccess, F
}
else if (fileMode == FileMode.OpenOrCreate)
{
- if ( fileAccess == FileAccess.Read )
+ if (fileAccess == FileAccess.Read)
return folder.OpenStreamForReadAsync(filePath).GetAwaiter().GetResult();
else
- return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.OpenIfExists).GetAwaiter().GetResult();
+ {
+ // Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning
+ var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult();
+ return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
+ }
}
else if (fileMode == FileMode.Truncate)
{
@@ -432,7 +458,10 @@ public Stream OpenFile (string file, FileMode fileMode, FileAccess fileAccess, F
else
{
//if (fileMode == FileMode.Append)
- return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.OpenIfExists).GetAwaiter().GetResult();
+ // Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning
+ folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult().OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
+ var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult();
+ return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
}
#else
return File.Open(filePath, fileMode, fileAccess, fileShare);
Oops, something went wrong.

0 comments on commit c0dd813

Please sign in to comment.