public byte[] CreateMidiFile() { var loader = File.ReadAllBytes(_filePath); switch (_extension) { case ".gp3": _gpfile = new GP3File(loader); _gpfile.readSong(); break; case ".gp4": _gpfile = new GP4File(loader); _gpfile.readSong(); break; case ".gp5": _gpfile = new GP5File(loader); _gpfile.readSong(); break; case ".gpx": _gpfile = new GP6File(loader); _gpfile.readSong(); _gpfile = _gpfile.self; //Replace with transferred GP5 file break; case ".gp": var stream = new MemoryStream(); using (var unzip = new Unzip(_filePath)) { unzip.Extract("Content/score.gpif", stream); stream.Position = 0; var sr = new StreamReader(stream); var gp7Xml = sr.ReadToEnd(); _gpfile = new GP7File(gp7Xml); _gpfile.readSong(); _gpfile = _gpfile.self; //Replace with transferred GP5 file } break; default: Logger.Error("Unknown File Format"); break; } Logger.Debug("Done"); var song = new Native.Format(_gpfile); return(song.ToMidi().createBytes().ToArray()); }
public string DownloadData() { WebClient wc = new WebClient(); wc.DownloadFile(cmd, "Resource/subjectfile.zip"); using (var unzip = new Unzip("Resource/subjectfile.zip")) { string file = "error"; // list all files in the archive foreach (var fileName in unzip.FileNames) { file = fileName; } // extract single file to a specifie4d location unzip.Extract(file, "Resource/" + file); return(result = "Resource/" + file); } }
/// <summary> /// Coroutine that downloads the update file and installs it /// </summary> /// <returns></returns> public IEnumerator <float> DownloadUpdate() { if (state == UpdaterState.Ready) { // Creates a web request to the github repository based on the selected update stream if (updateStream == UpdateStream.Beta) { request = new UnityWebRequest("https://github.com/Cibbi/Toony-standard/archive/" + githubBetaJSON.sha + ".zip"); file = new DownloadHandlerFile(Application.dataPath + "/toonyStandard.zip"); } else { request = new UnityWebRequest(githubReleaseJSON.assets[0].browser_download_url); file = new DownloadHandlerFile(Application.dataPath + "/toonyStandard.unitypackage"); } request.method = UnityWebRequest.kHttpVerbGET; file.removeFileOnAbort = true; request.downloadHandler = file; request.SendWebRequest(); state = UpdaterState.Downloading; // Main check cycle that waits for the downloaded file, like the update check execution is paused every cycle to not block // normal window execution while (state == UpdaterState.Downloading) { yield return(0.5f); // Executed if the request is done if (request.isDone) { state = UpdaterState.Downloaded; TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath)); // If the update stream is the beta one the downloaded file is a zip file, meaning that we have to extract it manually, fortunately a guy called Yallie made a simple // extraction class that handles the basic stuff needed here, check him over https://github.com/yallie/unzip if (updateStream == UpdateStream.Beta) { string localFolder = TSConstants.LocalShaderFolder; Unzip zip = new Unzip(Application.dataPath + "/toonyStandard.zip"); // Deleting the old Toony standard version if (Directory.Exists(TSConstants.LocalShaderFolder)) { Directory.Delete(TSConstants.LocalShaderFolder, true); } // For each file in the zip we change the github repository path with the more user friendly one used on the releases, and then extract that file in that path foreach (string fileName in zip.FileNames) { string newDir = fileName.Replace("Toony-standard-" + githubBetaJSON.sha, localFolder); if (!Directory.Exists(Path.GetDirectoryName(newDir))) { Directory.CreateDirectory(Path.GetDirectoryName(newDir)); } zip.Extract(fileName, newDir); } // Disposing of the zip, this is important cause without doing it the zip file cannot be deleted afterwards zip.Dispose(); // Creation of the updated version.json file for this beta version, cause the one that comes in the zip does not contain the sha of the commit used when checking updates // Since it's impossible to know a commit sha before doing such commit. LocalVersionJSON local = new LocalVersionJSON(); local.beta = true; local.betaSha = githubBetaJSON.sha; local.version = "beta"; local.lastCheck = DateTime.Now.ToString(); File.WriteAllText(TSConstants.LocalJSONPath, JsonUtility.ToJson(local)); // The asset database is refreshed to be sure that the zip file is actually detected from the asset database for its deletion File.Delete(Application.dataPath + "/toonyStandard.zip"); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); } // If the update stream is the release one the downloaded file is the latest unitypackage that can be found here https://github.com/Cibbi/Toony-standard/releases // Since it's a unitypackage its installation is relatively easy, but we still delete the old version first for safety else { if (Directory.Exists(TSConstants.LocalShaderFolder)) { Directory.Delete(TSConstants.LocalShaderFolder, true); } AssetDatabase.ImportPackage(Application.dataPath + "/toonyStandard.unitypackage", false); AssetDatabase.Refresh(); AssetDatabase.DeleteAsset("Assets/toonyStandard.unitypackage"); } File.WriteAllText(TSConstants.OldSettingsJSONPath, JsonUtility.ToJson(settings)); } // Executed if the request got an error response if (request.isNetworkError || request.isHttpError) { Debug.Log("Toony Standard: network error during downlaod, please retry later"); } } } }
static void Main(string[] args) { string zipPath = @"c:\\Users\\sliu\\desktop\\yourfile.zip"; string csvPath = @"c:\\Users\\sliu\\desktop\\yourfile.csv"; Stream strCsv = File.OpenRead(csvPath); if (csvPath.Contains(".csv")) { StreamReader reader = new StreamReader(strCsv); string[] columnsInit = reader.ReadLine().Split(','); string[] values = reader.ReadLine().Split(','); List <string> columns = new List <string>(); Decimal value; for (int i = 0; i < columnsInit.Length; i++) { if (values[i] == "") { values[i] = "0"; } if (!columnsInit[i].ToLower().Contains("lat") && !columnsInit[i].ToLower().Contains("lon") && Decimal.TryParse(values[i], out value)) { columns.Add(columnsInit[i]); } } reader.Dispose(); } Stream fs = File.OpenRead(zipPath); Stream strShp = new MemoryStream(); Stream strShx = new MemoryStream(); Stream strDbf = new MemoryStream(); if (zipPath.Contains(".zip")) { Unzip unzip = new Unzip(fs); Entry[] entries = unzip.Entries; foreach (Entry entry in entries) { if (entry.Name.Contains(".shp")) { strShp = unzip.Extract(entry); if (strShp.CanSeek) { strShp.Seek(0, SeekOrigin.Begin); } } if (entry.Name.Contains(".shx")) { strShx = unzip.Extract(entry); if (strShx.CanSeek) { strShx.Seek(0, SeekOrigin.Begin); } } if (entry.Name.Contains(".dbf")) { strDbf = unzip.Extract(entry); if (strDbf.CanSeek) { strDbf.Seek(0, SeekOrigin.Begin); } } } //Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(fs); //foreach (ZipEntry e in zip) //{ // if (e.FileName.Contains(".shp")) // { // e.Extract(strShp); // if (strShp.CanSeek) // { // strShp.Seek(0, SeekOrigin.Begin); // } // } // if (e.FileName.Contains(".shx")) // { // e.Extract(strShx); // if (strShx.CanSeek) // { // strShx.Seek(0, SeekOrigin.Begin); // } // } // if (e.FileName.Contains(".dbf")) // { // e.Extract(strDbf); // if (strDbf.CanSeek) // { // strDbf.Seek(0, SeekOrigin.Begin); // } // } //} if (strShp != null && strShx != null && strDbf != null) { using (Shapefile shapefile = new Shapefile(strShp, strShx, strDbf)) { //Console.WriteLine("ShapefileDemo Dumping {0}", args[0]); Console.WriteLine(); // a shapefile contains one type of shape (and possibly null shapes) Console.WriteLine("Type: {0}, Shapes: {1:n0}", shapefile.Type, shapefile.Count); // a shapefile also defines a bounding box for all shapes in the file Console.WriteLine("Bounds: {0},{1} -> {2},{3}", shapefile.BoundingBox.Left, shapefile.BoundingBox.Top, shapefile.BoundingBox.Right, shapefile.BoundingBox.Bottom); Console.WriteLine(); // enumerate all shapes foreach (Shape shape in shapefile) { Console.WriteLine("----------------------------------------"); Console.WriteLine("Shape {0:n0}, Type {1}", shape.RecordNumber, shape.Type); // each shape may have associated metadata string[] metadataNames = shape.GetMetadataNames(); if (metadataNames != null) { Console.WriteLine("Field data:"); foreach (string metadataName in metadataNames) { Console.WriteLine("{0}={1}", metadataName, shape.GetMetadata(metadataName)); } Console.WriteLine(); } // cast shape based on the type switch (shape.Type) { case ShapeType.Point: // a point is just a single x/y point ShapePoint shapePoint = shape as ShapePoint; Console.WriteLine("Point={0},{1}", shapePoint.Point.X, shapePoint.Point.Y); break; case ShapeType.Polygon: // a polygon contains one or more parts - each part is a list of points which // are clockwise for boundaries and anti-clockwise for holes // see http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf ShapePolygon shapePolygon = shape as ShapePolygon; foreach (PointD[] part in shapePolygon.Parts) { Console.WriteLine("Polygon part:"); foreach (PointD point in part) { Console.WriteLine("{0}, {1}", point.X, point.Y); } Console.WriteLine(); } break; default: // and so on for other types... break; } Console.WriteLine("----------------------------------------"); Console.WriteLine(); } } strShp.Dispose(); strShx.Dispose(); strDbf.Dispose(); } } // Pass the path to the shapefile in as the command line argument //args = new string[] { "C:\\Users\\sliu\\Desktop\\TestData\\Home West 1998 Corn\\Home West 1998 Corn.shp" }; //if ((args.Length == 0) || (!File.Exists(args[0]))) //{ // Console.WriteLine("Usage: ShapefileDemo <shapefile.shp>"); // return; //} // construct shapefile with the path to the .shp file //using (Shapefile shapefile = new Shapefile(args[0])) //{ // strShp.Close(); // strShx.Close(); // strDbf.Close(); // Console.WriteLine("ShapefileDemo Dumping {0}", args[0]); // Console.WriteLine(); // // a shapefile contains one type of shape (and possibly null shapes) // Console.WriteLine("Type: {0}, Shapes: {1:n0}", shapefile.Type, shapefile.Count); // // a shapefile also defines a bounding box for all shapes in the file // Console.WriteLine("Bounds: {0},{1} -> {2},{3}", // shapefile.BoundingBox.Left, // shapefile.BoundingBox.Top, // shapefile.BoundingBox.Right, // shapefile.BoundingBox.Bottom); // Console.WriteLine(); // // enumerate all shapes // foreach (Shape shape in shapefile) // { // Console.WriteLine("----------------------------------------"); // Console.WriteLine("Shape {0:n0}, Type {1}", shape.RecordNumber, shape.Type); // // each shape may have associated metadata // string[] metadataNames = shape.GetMetadataNames(); // if (metadataNames != null) // { // Console.WriteLine("Field data:"); // foreach (string metadataName in metadataNames) // { // Console.WriteLine("{0}={1} ({2})", metadataName, shape.GetMetadata(metadataName), shape.DataRecord.GetDataTypeName(shape.DataRecord.GetOrdinal(metadataName))); // } // Console.WriteLine(); // } // // cast shape based on the type // switch (shape.Type) // { // case ShapeType.Point: // // a point is just a single x/y point // ShapePoint shapePoint = shape as ShapePoint; // Console.WriteLine("Point={0},{1}", shapePoint.Point.X, shapePoint.Point.Y); // break; // case ShapeType.Polygon: // // a polygon contains one or more parts - each part is a list of points which // // are clockwise for boundaries and anti-clockwise for holes // // see http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf // ShapePolygon shapePolygon = shape as ShapePolygon; // foreach (PointD[] part in shapePolygon.Parts) // { // Console.WriteLine("Polygon part:"); // foreach (PointD point in part) // { // Console.WriteLine("{0}, {1}", point.X, point.Y); // } // Console.WriteLine(); // } // break; // default: // // and so on for other types... // break; // } // Console.WriteLine("----------------------------------------"); // Console.WriteLine(); // } //} Console.WriteLine("Done"); Console.WriteLine(); }
public static GPFile Create(string filename, byte[] content) { int version = 7; string fileEnding = Path.GetExtension(filename); if (fileEnding.Equals(".gp3")) { version = 3; } if (fileEnding.Equals(".gp4")) { version = 4; } if (fileEnding.Equals(".gp5")) { version = 5; } if (fileEnding.Equals(".gpx")) { version = 6; } if (fileEnding.Equals(".gp")) { version = 7; } GPFile gpfile = null; switch (version) { case 3: gpfile = new GP3File(content); gpfile.readSong(); break; case 4: gpfile = new GP4File(content); gpfile.readSong(); break; case 5: gpfile = new GP5File(content); gpfile.readSong(); break; case 6: gpfile = new GP6File(content); gpfile.readSong(); gpfile = gpfile.self; //Replace with transferred GP5 file break; case 7: string archiveName = filename.Substring(8).Replace("%20", " "); byte[] buffer = new byte[8200000]; MemoryStream stream = new MemoryStream(buffer); using (var unzip = new Unzip(archiveName)) { //Console.WriteLine("Listing files in the archive:"); // ListFiles(unzip); unzip.Extract("Content/score.gpif", stream); stream.Position = 0; var sr = new StreamReader(stream); string gp7xml = sr.ReadToEnd(); gpfile = new GP7File(gp7xml); gpfile.readSong(); gpfile = gpfile.self; //Replace with transferred GP5 file } break; default: Log.Debug("Unknown File Format"); break; } return(gpfile); }
private IEnumerator OutputRoutine(string url) { var loader = new WWW(url); yield return(loader); //Detect Version by Filename int version = 7; string fileEnding = Path.GetExtension(url); if (fileEnding.Equals(".gp3")) { version = 3; } if (fileEnding.Equals(".gp4")) { version = 4; } if (fileEnding.Equals(".gp5")) { version = 5; } if (fileEnding.Equals(".gpx")) { version = 6; } if (fileEnding.Equals(".gp")) { version = 7; } switch (version) { case 3: gpfile = new GP3File(loader.bytes); gpfile.readSong(); break; case 4: gpfile = new GP4File(loader.bytes); gpfile.readSong(); break; case 5: gpfile = new GP5File(loader.bytes); gpfile.readSong(); break; case 6: gpfile = new GP6File(loader.bytes); gpfile.readSong(); gpfile = gpfile.self; //Replace with transferred GP5 file break; case 7: string archiveName = url.Substring(8).Replace("%20", " "); byte[] buffer = new byte[8200000]; MemoryStream stream = new MemoryStream(buffer); using (var unzip = new Unzip(archiveName)) { //Console.WriteLine("Listing files in the archive:"); ListFiles(unzip); unzip.Extract("Content/score.gpif", stream); stream.Position = 0; var sr = new StreamReader(stream); string gp7xml = sr.ReadToEnd(); gpfile = new GP7File(gp7xml); gpfile.readSong(); gpfile = gpfile.self; //Replace with transferred GP5 file } break; default: Debug.Log("Unknown File Format"); break; } Debug.Log("Done"); var song = new Native.NativeFormat(gpfile); var midi = song.toMidi(); List <byte> data = midi.createBytes(); var dataArray = data.ToArray(); using (var fs = new FileStream("output.mid", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Write(dataArray, 0, dataArray.Length); } //Create Example Track (delete) /* * MidiExport.MidiExport midi = new MidiExport.MidiExport(); * midi.fileType = 2; * midi.ticksPerBeat = 960; * * MidiExport.MidiTrack track = new MidiExport.MidiTrack(); * track.messages.Add(new MidiExport.MidiMessage("track_name",new string[] { "untitled" },0)); * track.messages.Add(new MidiExport.MidiMessage("time_signature", new string[] {"4","4","24","8" }, 0)); * track.messages.Add(new MidiExport.MidiMessage("control_change", new string[] { "0","7", "100" }, 0)); * track.messages.Add(new MidiExport.MidiMessage("program_change", new string[] { "0", "48" }, 0)); * track.messages.Add(new MidiExport.MidiMessage("note_on", new string[] { "0", "55","91" }, 0)); * track.messages.Add(new MidiExport.MidiMessage("note_on", new string[] { "0", "55", "0" }, 256)); * track.messages.Add(new MidiExport.MidiMessage("end_of_track", new string[] { }, 0)); * midi.midiTracks.Add(track); * midi.createBytes(); */ }