Last active
August 29, 2015 13:59
-
-
Save rlabrecque/10949932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Author: Riley Labrecque | |
License: Public Domain where acceptable. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy and modify this file as you see fit. | |
Created for FNA. | |
''' | |
import os | |
g_SystemList = [ | |
'System', | |
'System.Collections', | |
'System.Collections.Generic', | |
'System.Collections.ObjectModel', | |
'System.ComponentModel', | |
'System.Diagnostics', | |
'System.Globalization', | |
'System.IO', | |
'System.IO.Path', | |
'System.Linq', | |
'System.Reflection', | |
'System.Resources', | |
'System.Runtime.InteropServices', | |
'System.Runtime.Remoting.Messaging', | |
'System.Runtime.Serialization', | |
'System.Text', | |
'System.Text.RegularExpressions', | |
'System.Threading', | |
'System.Threading.Tasks', | |
'System.Xml.Serialization', | |
] | |
g_ExternalList = [ | |
'OpenTK', | |
'OpenTK.Audio.OpenAL', | |
'OpenTK.Graphics.ES20', | |
'OpenTK.Graphics.OpenGL', | |
'Sce.PlayStation.Core.Graphics', | |
'SDL2', | |
'SharpDX', | |
'SharpDX.Direct3D', | |
'SharpDX.Direct3D11', | |
'SharpDX.DXGI', | |
] | |
g_InternalList = [ | |
'Microsoft.Xna', | |
'Microsoft.Xna.Framework', | |
'Microsoft.Xna.Framework.Audio', | |
'Microsoft.Xna.Framework.Content', | |
'Microsoft.Xna.Framework.Graphics', | |
'Microsoft.Xna.Framework.Input', | |
'Microsoft.Xna.Framework.Input.Touch', | |
'Microsoft.Xna.Framework.Media', | |
] | |
#Manually will have to do the following files: | |
g_SkipList = [ | |
'SDL2/SDL2_GameWindow.cs', # [ERROR] Garbage between using statements - #if conditionals | |
'SDL2/Media/VideoPlayer.cs', # [ERROR] Garbage between using statements - #if conditionals | |
'/Threading.cs', # [ERROR] Garbage between using statements - #if conditionals | |
] | |
g_FolderList = [ | |
'Audio', | |
'Content', | |
'Content/ContentReaders', | |
#'GamerServices', | |
'Graphics', | |
#'Graphics/Effect', | |
#'Grahpics/Effect/Resources', | |
'Graphics/PackedVector', | |
#'Graphics/Shader', | |
'Graphics/States', | |
'Graphics/Vertices', | |
'Input', | |
'Input/Touch', | |
'Media', | |
#'Net', | |
#'Properties', | |
'SDL2', | |
'SDL2/Input', | |
'SDL2/Media', | |
'Storage', | |
#'Utilities', | |
'', | |
] | |
def main(): | |
files = [] | |
for folder in g_FolderList: | |
files.extend([folder + '/' + f for f in os.listdir('MonoGame.Framework/' + folder) if os.path.isfile(os.path.join('MonoGame.Framework/' + folder, f))]) | |
try: | |
os.makedirs('autogen/' + folder) | |
except OSError: | |
pass | |
for filename in g_SkipList: | |
with open('MonoGame.Framework/' + filename, 'r') as f: | |
with open('autogen/' + filename, 'wb') as out: | |
for line in f: | |
out.write(bytes(line, 'UTF-8')) | |
files.remove(filename) | |
for filename in files: | |
print('\n===========================') | |
print('Opening: "' + filename + '"') | |
with open('MonoGame.Framework/' + filename, 'r') as f: | |
lines = f.read().splitlines() | |
nFirstUsingStatement = 0 | |
nLastUsingStatement = 0 | |
nRegiolinetartpos = 0 | |
nRegionEndpos = 0 | |
usingsSystem = [] | |
usingsExternal = [] | |
usingsInternal = [] | |
for linenum, line in enumerate(lines): | |
linenum += 1 | |
line = line.rstrip() | |
if len(line.strip()) == 0: | |
continue | |
if line.startswith('using'): | |
namespace = line[len('using '):-1] | |
if namespace in g_SystemList: | |
usingsSystem.append(namespace) | |
elif namespace in g_ExternalList: | |
usingsExternal.append(namespace) | |
elif namespace in g_InternalList: | |
usingsInternal.append(namespace) | |
else: | |
raise Exception('[ERROR] - Unknown Namespace - "' + namespace + '"') | |
nLastUsingStatement = linenum | |
if nFirstUsingStatement == 0: | |
nFirstUsingStatement = linenum | |
if line == '#region Using Statements': | |
nRegiolinetartpos = linenum | |
elif nRegiolinetartpos != 0 and nRegionEndpos == 0 and line == '#endregion': | |
nRegionEndpos = linenum | |
if nRegiolinetartpos != 0: | |
if nFirstUsingStatement < nRegiolinetartpos or nLastUsingStatement > nRegionEndpos: | |
raise Exception('[ERROR]: using statement not within a region - "' + line + '"') | |
for line in lines[nFirstUsingStatement:nLastUsingStatement]: | |
if not line.startswith('using') and len(line.strip()) != 0: | |
raise Exception('[ERROR] Garbage between using statements - "' + line + '"') | |
with open('autogen/' + filename, 'wb') as out: | |
if nFirstUsingStatement != 0: | |
for line in lines[:nFirstUsingStatement-1]: | |
out.write(bytes(line + '\n', 'UTF-8')) | |
if nRegiolinetartpos == 0: | |
out.write(bytes('#region Using Statements\n', 'UTF-8')) | |
for line in sorted(usingsSystem): | |
out.write(bytes('using ' + line + ';\n', 'UTF-8')) | |
if len(usingsSystem) != 0 and len(usingsExternal) != 0: | |
out.write(bytes('\n', 'UTF-8')) | |
for line in sorted(usingsExternal): | |
out.write(bytes('using ' + line + ';\n', 'UTF-8')) | |
if len(usingsExternal) != 0 and len(usingsInternal) != 0: | |
out.write(bytes('\n', 'UTF-8')) | |
elif len(usingsSystem) != 0 and len(usingsInternal) != 0: | |
out.write(bytes('\n', 'UTF-8')) | |
for line in sorted(usingsInternal): | |
out.write(bytes('using ' + line + ';\n', 'UTF-8')) | |
if nFirstUsingStatement != 0 and nRegiolinetartpos == 0: | |
out.write(bytes('#endregion\n', 'UTF-8')) | |
for line in lines[nLastUsingStatement:]: | |
out.write(bytes(line + '\n', 'UTF-8')) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment