コード例 #1
0
 public static string CompressGo( string path,string pack="" )
 {
     Parser.Source res = new Parser.Source();
     StreamReader sr = new StreamReader( path );
     while ( !sr.EndOfStream ) {
         string line = sr.ReadLine( ).Trim( );
         if ( line.StartsWith( "package" ) ) {
             if ( !line.Trim( ).EndsWith( " " + pack ) && pack != "" ) {
                 sr.Close( );
                 return "";
             }
             res.AppendLine( line.Trim( ) );
         } else if ( line.StartsWith( "func" ) ) {
             res.AppendLine( ( line.Contains( '{' ) ? line.Remove( line.LastIndexOf( '{' ) ) : line ).Trim( ) );
             if ( line.Contains( '{' ) && !line.Contains( '}' ) ) {
                 int i = 1;
                 while ( i > 0 ) {
                     line = sr.ReadLine( );
                     while ( line.Contains( "\"" ) ) {
                         int start = line.IndexOf( '"' );
                         line = line.Remove( start, line.IndexOf( '"', start + 1 ) - start + 1 );
                     }
                     i += line.Count( '{' ) - line.Count( '}' );
                 }
             }
         } else if ( line.StartsWith( "type" ) ) {
             res.AppendLine( line.Trim( ) );
             if ( line.Contains( '{' ) && !line.Contains( '}' ) ) {
                 int i = 1;
                 while ( i > 0 ) {
                     line = sr.ReadLine( );
                     while ( line.Contains( "\"" ) ) {
                         int start = line.IndexOf( '"' );
                         line = line.Remove( start, line.IndexOf( '"', start + 1 ) - start );
                     }
                     i += line.Count( '{' ) - line.Count( '}' );
                     res.AppendLine( line );
                 }
             }
         } else if ( line.StartsWith( "var" ) ) {
             if ( line.Contains( "=" ) )
                 line = line.Remove( line.IndexOf( '=' ) );
             res.AppendLine( line.Trim( ) );
         }
     }
     sr.Close( );
     return res.Content;
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: VarocalCross/Varocal
 private void buildProjectToolStripMenuItem1_Click( object sender, EventArgs e )
 {
     DateTime dt = DateTime.Now;
     TreeNode project = null;
     if ( _TabControl1.Items.Count == 0 ) {
         if ( treeView1.Nodes.Count == 0 ) {
             MessageBox.Show( this,"To build one you should open a project (See File->Open or File->New)" );
             return;
         }
         project = treeView1.Nodes[ 0 ];
     } else {
         _TabControl1.Invalidate( );
         foreach ( TreeNode node in treeView1.Nodes )
             if ( _TabControl1.SelectedItem.Tag is string ) {
                 if ( ( _TabControl1.SelectedItem.Tag as string ).Contains( node.Tag as string ) ) {
                     project = node;
                     break;
                 }
             } else if ( _TabControl1.SelectedItem.Controls[ 0 ] is FormProperties ) {
                 if ( ( ( ( FormProperties )_TabControl1.SelectedItem.Controls[ 0 ] ).Path ).Contains( node.Tag as string ) ) {
                     project = node;
                     break;
                 }
             }
         if ( project == null ) {
             MessageBox.Show( this,"To build one you should open a project (See File->Open or File->New)" );
             return;
         }
         FormProperties fp = default( FormProperties );
         bool setted = false;
         foreach ( FATabStripItem item in _TabControl1.items ) {
                 if ( item.Controls[ 0 ] is FormProperties && !setted ) {
                     if ( ( ( ( FormProperties )item.Controls[ 0 ] ).Path ).StartsWith( project.Tag as string ) ) {
                         fp = ( FormProperties )item.Controls[ 0 ];
                         setted = true;
                     }
                 }
             SaveTab( item );
         }
         if ( !setted )
             fp = new FormProperties( Path.Combine( project.Tag as string, "projectdata.dat" ) );
         fp.ver_3.Value += 1;
         fp.MemoryCore.Save( Path.Combine( project.Tag as string, "projectdata.dat" ) );
         try {
             ( ( FATabStripItem )fp.Parent ).Saved = true;
         } catch {
         }
     }
     List<TreeNode> ls = new List<TreeNode>( );
     ls.Add( project );
     BuildResult result = null;
     FormProperties prop = new FormProperties( Path.Combine( project.Tag as string, "projectdata.dat" ) );
     Package package = new Package( );
     string cmpdir = "cmpdir";
     if ( prop.ProjectType.Text == "Package" ) {
         package.ID = random.Next( );
         cmpdir = "src\\pkg\\" + package.ID;
     }
     while ( ls.Count != 0 ) {
         TreeNode node = ls[ 0 ];
         ls.RemoveAt( 0 );
         if ( node.Parent == null || node.Tag == null ) {
             foreach ( TreeNode node2 in node.Nodes )
                 ls.Add( node2 );
             continue;
         }
         string path = node.Tag as string;
         if ( path.EndsWith( ".cs" ) || path.EndsWith( ".go" ) || path.EndsWith( ".c" ) )
             File.Copy( Path.GetFileName( path ), path );
         else
             build.AddSource( File.ReadAllText( path ) );
     }
     string bat = Path.GetRandomFileName( ) + ".cmd";
     try {
         ProcessStartInfo psi = new ProcessStartInfo( "cmd", "/C " + bat );
         psi.CreateNoWindow = true;
         psi.UseShellExecute = true;
         File.WriteAllText( bat, prop.PreBuildText.Text );
         Process.Start( psi ).WaitForExit( );
         List<String> packages = new List<string>( );
         foreach ( DataGridViewRow row in prop.packs.Rows ) {
             packages.Add( Path.GetFullPath( Path.Combine( "pkg\\" + Build.GeneratePlatform( ( prop.cmb_platform.SelectedIndex == 0 ? Build.Platform.Windows :
     ( prop.cmb_platform.SelectedIndex == 1 ? Build.Platform.Linux : Build.Platform.Mac ) ),
     prop.ProjectSet.Text.Contains( "64" ) ), ( string )row.Cells[ 2 ].Value ) + ".obj" ) );
         }
         build.InterpretTo( cmpdir, out result, prop.ProjectType.Text == "Package"
             , prop.txt_name.Text, package.ID );
         if ( result.Type != BuildResultType.None ) {
             Parser.Source source = new Parser.Source( );
             foreach ( Parser.CodeErrorException exception in ( Parser.CodeErrorException[ ] )result.Result )
                 source.AppendLine( exception.Message );
             MessageBox.Show(this, source.Content );
             if ( File.Exists( bat ) )
                 File.Delete( bat );
             File.WriteAllText( bat, prop.PostBuildText.Text );
             Process.Start( psi ).WaitForExit( );
             return;
         } else {
             build.Linking( cmpdir, out result, ( int )prop.WarnLvl.Value, prop.WarnAsErr.Checked,
                 prop.ProjectType.Text == "Package", packages, prop.txt_name.Text );
             if ( result.Type != BuildResultType.None ) {
                 Parser.Source source = new Parser.Source( );
                 foreach ( CompilerError error in ( CompilerError[ ] )result.Result )
                     source.AppendLine( error.ErrorText );
                 MessageBox.Show(this, source.Content );
                 if ( File.Exists( bat ) )
                     File.Delete( bat );
                 File.WriteAllText( bat, prop.PostBuildText.Text );
                 Process.Start( psi ).WaitForExit( );
                 return;
             } else {
                 build.Analyzing( cmpdir, prop.ProjectType.Text == "Package", prop.txt_name.Text, packages,
                     ( prop.cmb_platform.SelectedIndex == 0 ? Build.Platform.Windows :
             ( prop.cmb_platform.SelectedIndex == 1 ? Build.Platform.Linux : Build.Platform.Mac ) ), prop.ProjectSet.Text.Contains( "64" )
             , cmpdir, package.ID );
                 string output = build.Compiling( cmpdir, out result, prop.UPXComp.Checked,
                     ( prop.cmb_platform.SelectedIndex == 0 ? Build.Platform.Windows :
             ( prop.cmb_platform.SelectedIndex == 1 ? Build.Platform.Linux : Build.Platform.Mac ) ), prop.ProjectSet.Text.Contains( "64" ), prop.ProjectType.Text == "Package" );
                 if ( result.Type != BuildResultType.None ) {
                     Parser.Source source = new Parser.Source( );
                     foreach ( CompileError error in ( CompileError[ ] )result.Result )
                         source.AppendLine( error.FullText );
                     MessageBox.Show(this, source.Content );
                     if ( File.Exists( bat ) )
                         File.Delete( bat );
                     File.WriteAllText( bat, prop.PostBuildText.Text );
                     Process.Start( psi ).WaitForExit( );
                     return;
                 }
                 if ( prop.ProjectType.Text == "Package" ) {
                     if ( Directory.Exists( "pkgcmp" ) )
                         Directory.Delete( "pkgcmp", true );
                     Directory.CreateDirectory( "pkgcmp" );
                     var v = new ZipForge( );
                     v.FileName = Path.GetFullPath( Path.Combine( project.Tag as string, "build\\release\\" + prop.txt_name.Text + ".vpak" ) );
                     v.OpenArchive( System.IO.FileMode.Create );
                     v.BaseDir = Path.GetFullPath( cmpdir );
                     package.Name = prop.txt_name.Text;
                     package.PlatformString = Environment.GetEnvironmentVariable( "GOOS" ) + "_" + Environment.GetEnvironmentVariable( "GOARCH" );
                     package.Platform = ( prop.cmb_platform.SelectedIndex == 0 ? Build.Platform.Windows :
             ( prop.cmb_platform.SelectedIndex == 1 ? Build.Platform.Linux : Build.Platform.Mac ) );
                     package.is64X = prop.ProjectSet.Text.Contains( "64" );
                     package.DefaultNamespace = prop.txt_namespace.Text;
                     package.Description = prop.txt_description.Text;
                     package.Version = string.Join( ".", new string[ ] {
                     prop.ver_1.Value.ToString( ),
                     prop.ver_2.Value.ToString( ),
                     prop.ver_3.Value.ToString( ),
                     prop.ver_4.Value.ToString( ) } );
                     MemorizePortable mem = new MemorizePortable( );
                     mem.AddOwner( package );
                     mem.Save( Path.Combine( v.BaseDir, "install.dat" ) );
                     File.Move( output, Path.Combine( v.BaseDir, prop.txt_name.Text + ".a" ) );
                     foreach ( string file in Directory.GetFiles( v.BaseDir,"*.go" ) ) {
                         string newcode = PackageInstallation.CompressGo( file );
                         File.Delete( file );
                         File.WriteAllText( file, newcode );
                     }
                     v.AddFiles( Path.Combine( v.BaseDir, "*.*" ) );
                     v.CloseArchive( );
                 } else {
                     string exe = Path.Combine( project.Tag as string, "build\\release\\" + prop.txt_name.Text + ".exe" );
                     if ( File.Exists( exe ) )
                         File.Delete( exe );
                     File.Move( output, exe );
                 }
             }
         }
         if ( File.Exists( bat ) )
             File.Delete( bat );
         File.WriteAllText( bat, prop.PostBuildText.Text );
         Process.Start( psi ).WaitForExit( );
         MessageBox.Show( this,"Build's time: " + ( DateTime.Now - dt ).TotalMilliseconds );
     } finally {
         File.Delete( bat );
         if ( Directory.Exists( "pkgcmp" ) )
             Directory.Delete( "pkgcmp", true );
         Directory.Delete( cmpdir, true );
     }
 }