C# распаковывает файлы
1 using Microsoft.VisualBasic; 2 using Microsoft.VisualBasic.CompilerServices; 3 using System; 4 using System.Collections; 5 using System.Collections.Generic; 6 using System.ComponentModel; 7 using System.Data; 8 using System.Drawing; 9 using System.IO; 10 using System.IO.Compression; 11 using System.Linq; 12 using System.Runtime.CompilerServices; 13 using System.Text; 14 using System.Threading.Tasks; 15 using System.Windows.Forms; 16 using System.Xml; 17 18 namespace SD 19 { 20 public partial class Form1 : Form 21 { 22 public Form1() 23 { 24 InitializeComponent(); 25 } 26 private string fileName; 27 28 private void Form1_Load(object sender, EventArgs e) 29 { 30 } 31 private void button1_Click(object sender, EventArgs e) 32 { 33 List<string> filenames = FindFiles(path.Text, exten.Text,check.Checked); 34 lstFiles.Items.Clear(); 35 foreach (string filename in filenames) 36 { 37 lstFiles.Items.Add(filename); 38 } 39 } 40 private List<string> FindFiles(string dir_name, string patterns, bool search_subdirectories) 41 { 42 List<string> files = new List<string>(); 43 string[] pattern_array = patterns.Split(';'); 44 SearchOption search_option = SearchOption.AllDirectories; 45 foreach (string pattern in pattern_array) 46 { 47 foreach (string filename in Directory.GetFiles(dir_name, pattern, search_option)) 48 { 49 if (!files.Contains(filename)) files.Add(filename); 50 } 51 } 52 label1.Text = files.Count.ToString(); 53 files.Sort(); 54 return files; 55 } 56 private void lstFiles_SelectedIndexChanged(object sender, EventArgs e) 57 { 58 } 59 private byte[] DecompressArray(byte[] content) 60 { 61 byte[] array; 62 int num; 63 using (MemoryStream memoryStream = new MemoryStream()) 64 { 65 using (MemoryStream memoryStream1 = new MemoryStream(content)) 66 { 67 using (GZipStream gZipStream = new GZipStream(memoryStream1, CompressionMode.Decompress)) 68 { 69 byte[] numArray = new byte[1024]; 70 do 71 { 72 num = gZipStream.Read(numArray, 0, (int)numArray.Length); 73 memoryStream.Write(numArray, 0, num); 74 } 75 while (num > 0); 76 } 77 } 78 array = memoryStream.ToArray(); 79 } 80 return array; 81 } 82 private void UnzipDirectory(byte[] compressed, string outputPath) 83 { 84 IEnumerator enumerator = null; 85 IEnumerator enumerator1 = null; 86 if (!Directory.Exists(outputPath)) 87 { 88 Directory.CreateDirectory(outputPath); 89 } 90 byte[] numArray = this.DecompressArray(compressed); 91 XmlDocument xmlDocument = new XmlDocument(); 92 using (MemoryStream memoryStream = new MemoryStream(numArray)) 93 { 94 xmlDocument.Load(memoryStream); 95 XmlNode firstChild = xmlDocument.FirstChild; 96 XmlNode xmlNodes = firstChild.FirstChild; 97 XmlNode nextSibling = firstChild.FirstChild.NextSibling; 98 try 99 { 100 enumerator = xmlNodes.ChildNodes.GetEnumerator(); 101 while (enumerator.MoveNext()) 102 { 103 object objectValue = RuntimeHelpers.GetObjectValue(enumerator.Current); 104 Directory.CreateDirectory(Path.Combine(outputPath, ((XmlNode)objectValue).Attributes.Item(0).Value)); 105 } 106 } 107 finally 108 { 109 if (enumerator is IDisposable) 110 { 111 (enumerator as IDisposable).Dispose(); 112 } 113 } 114 try 115 { 116 enumerator1 = nextSibling.ChildNodes.GetEnumerator(); 117 while (enumerator1.MoveNext()) 118 { 119 object obj = RuntimeHelpers.GetObjectValue(enumerator1.Current); 120 string str = Path.Combine(outputPath, ((XmlNode)obj).Attributes.Item(0).Value); 121 byte[] numArray1 = Convert.FromBase64String(((XmlNode)obj).InnerText); 122 File.WriteAllBytes(str, numArray1); 123 } 124 } 125 finally 126 { 127 if (enumerator1 is IDisposable) 128 { 129 (enumerator1 as IDisposable).Dispose(); 130 } 131 } 132 } 133 } 134 private void lstFiles_DoubleClick(object sender, EventArgs e) 135 { 136 if (lstFiles.SelectedItem != null) 137 { 138 139 lstFiles.SelectedItem.ToString(); 140 FileInfo fileInfo = new FileInfo(fileName); 141 try 142 { 143 if (File.Exists(fileName)) 144 { 145 UnzipDirectory(File.ReadAllBytes(fileName), fileInfo.DirectoryName); 146 } 147 } 148 catch (Exception exception) 149 { 150 ProjectData.SetProjectError(exception); 151 Interaction.MsgBox("error", MsgBoxStyle.OkOnly, null); 152 ProjectData.ClearProjectError(); 153 return; 154 } 155 Interaction.MsgBox("Complete", MsgBoxStyle.OkOnly, null); 156 } 157 } 158 } 159 }
Что я уже пробовал:
Моя проблема заключается в том, что когда я выбираю файл из списка двойным щелчком мыши, код возврата с ошибкой в строке 140 значение не может быть нулевым...