public static String ZipFile(String sourcePath, String destinationPath, String zippedFilename, String rawFilename_Ext, String password) { String ZIP_File_Created_Successfully = "True"; try { ZipForge ZipForge1 = new ZipForge(); ZipForge1.FileName = destinationPath + @"\" + zippedFilename + ".zip"; // Create a new archive file ZipForge1.OpenArchive(FileMode.Create); if (password != "") { ZipForge1.Password = password; } // Set path to folder with the files to archive ZipForge1.BaseDir = sourcePath; // Add all files and directories from the source folder to the archive ZipForge1.AddFiles(rawFilename_Ext); ZipForge1.CloseArchive(); } catch (Exception zipEx) { ZIP_File_Created_Successfully = zipEx.Message.ToString(); } return(ZIP_File_Created_Successfully); }
/// <summary> /// запуск архивирования с настройками по умолчанию /// </summary> public static void Checet() { // Create an instance of the ZipForge class ZipForge archiver = new ZipForge(); try { archiver.FileName = @"C:\test.zip"; //Куда сохранить файл результата сжатия archiver.OpenArchive(System.IO.FileMode.Create); //Настраиваем дллку на работу с новым архивом archiver.BaseDir = @"C:\123"; //Папка где лежат все файлы для взятия // archiver.AddFiles("*.exe"); //Берём все файлы с расширением exe // archiver.AddFiles("*.dll"); //archiver.AddFiles("*.jpg"); archiver.AddFiles("*.*"); // archiver.BaseDir = @"D:\"; // archiver.AddFiles(@"d:\file.txt"); //Добавим один файл // archiver.AddFiles(@"d:\Test"); //Запакуем ещё и папку archiver.CloseArchive(); //Закрываем архив } //Ловим ошибки catch (ArchiverException ae) { Console.WriteLine("Message: {0}\t Произошла ошибка: {1}", ae.Message, ae.ErrorCode); Console.ReadLine(); } Console.WriteLine("Процес архивирования завершен....\t\n"); }
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 ); } }
private void button18_Click(object sender, EventArgs e) { //**************************** string filename = textBox1.Text; string filename1 = filename; string filename2 = textBox1.Text; filename += ".xml"; filename1 += ".rtf"; filename2 += ".zip"; string newfilename1 = Path.Combine("C:\\Users\\Vyshak\\Desktop\\PROJECT", textBox1.Text); string newfilenamezip = Path.Combine("C:\\Users\\Vyshak\\Desktop\\PROJECT", filename2); Directory.CreateDirectory(newfilename1); string newfilename = Path.Combine(newfilename1, filename); string newfilenamertf = Path.Combine(newfilename1, filename1); FileStream aFile = new FileStream(newfilename, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(aFile); sw.WriteLine("<Tempnum>" + Class1.tempnum + "</Tempnum>"); if ((Class1.tempnum == 1) || (Class1.tempnum == 2)) sw.WriteLine("<Text>" + textBox3.Text + "</Text>"); if((Class1.tempnum==2)||(Class1.tempnum==4)) { // sw.WriteLine(); sw.Write("<Video>"); sw.Write(Class1.videofilename); sw.WriteLine("</Video>"); // } if((Class1.tempnum==1)||(Class1.tempnum==3)||(Class1.tempnum==4)) { // sw.WriteLine(); sw.Write("<Image>"); sw.Write(Class1.imagefilename); sw.WriteLine("</Image>"); // } if(Class1.tempnum==3) { // sw.WriteLine(); sw.Write("<Audio>"); //Class1.audiopath = Path.GetFileName(sourcePath); sw.Write(Class1.audiopath); sw.WriteLine("</Audio>"); // } sw.WriteLine("<Richtext>" + filename1 + "</Richtext>"); if ((Class1.tempnum == 1) || (Class1.tempnum == 2) || (Class1.tempnum == 3)) { string question = textBox5.Text; sw.WriteLine("<QA><QUESTION>" + question + "</QUESTION>"); string answer1 = textBox6.Text; string answer2 = textBox7.Text; string answer3 = textBox8.Text; string answer4 = textBox9.Text; string correctanswer = textBox10.Text; sw.WriteLine("<ANSWER1>" + answer1 + "</ANSWER1>"); sw.WriteLine("<ANSWER2>" + answer2 + "</ANSWER2>"); sw.WriteLine("<ANSWER3>" + answer3 + "</ANSWER3>"); sw.WriteLine("<ANSWER4>" + answer4 + "</ANSWER4>"); sw.WriteLine("<CORRECTANSWER>" + correctanswer + "</CORRECTANSWER></QA>"); } sw.WriteLine("</doc></Manual>"); string str = richTextBox1.Text; richTextBox2.SaveFile(newfilenamertf, RichTextBoxStreamType.RichText); sw.Close(); //ZIPPING FILE ZipForge archiver = new ZipForge(); try { // Set the name of the archive file we want to create archiver.FileName = newfilenamezip; // Because we create a new archive, archiver.Password = "******"; // we set fileMode to System.IO.FileMode.Create archiver.OpenArchive(System.IO.FileMode.Create); // Set base (default) directory for all archive operations archiver.BaseDir = @"C:\Users\Vyshak\Desktop\PROJECT"; // Add the c:\Test folder to the archive with all subfolders archiver.AddFiles(newfilename1); archiver.CloseArchive(); } // Catch all exceptions of the ArchiverException type catch (ArchiverException ae) { Console.WriteLine("Message: {0}\t Error code: {1}", ae.Message, ae.ErrorCode); // Wait for the key to be pressed Console.ReadLine(); } //ZIP COMPLETE this.Close(); }