Esempio n. 1
0
        static int encrypt_archive(string file_path_name, string source_path)
        {
            //check if file already exists... if yes rename it
            try
            {
                if (File.Exists(file_path_name))
                {
                    File.Move(file_path_name, file_path_name + ".bak");
                }
            }
            catch (IOException)
            {
                System.Console.Out.WriteLine("Error: Could not rename existing TAH file.");
                return(-1);
            }
            Encrypter encrypter = new Encrypter();

            //read in files from source path, do not compress them now.
            //全ディレクトリ名
            string[] directories = Directory.GetDirectories(source_path, "*", SearchOption.AllDirectories);

            {
                string   dirname = source_path;
                string[] files   = Directory.GetFiles(dirname);
                foreach (string file in files)
                {
                    encrypter.Add(file);
                }
            }
            for (int i = 0; i < directories.Length; i++)
            {
                string   dirname = directories[i];
                string[] files   = Directory.GetFiles(dirname);
                foreach (string file in files)
                {
                    encrypter.Add(file);
                }
            }

            encrypter.SourcePath         = source_path;
            encrypter.GetFileEntryStream = delegate(string true_file_name)
            {
                return(File.OpenRead(true_file_name));
            };
            encrypter.Save(file_path_name);
            return(0);
        }
Esempio n. 2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            Encrypter encrypter = new Encrypter();

            encrypter.SourcePath = @".";

            Dictionary <string, TAHEntry> entries = new Dictionary <string, TAHEntry>();

            foreach (TAHEntry entry in decrypter.Entries)
            {
                string ext = Path.GetExtension(entry.file_name).ToLower();
                if (ext == ".tmo")
                {
                    string true_file_name = encrypter.SourcePath + "/" + entry.file_name;
                    entries[true_file_name] = entry;
                    encrypter.Add(true_file_name);
                }
            }
            int entries_count = encrypter.Count;
            int current_index = 0;

            encrypter.GetFileEntryStream = delegate(string true_file_name)
            {
                Console.WriteLine("compressing {0}", true_file_name);
                TAHEntry entry = entries[true_file_name];
                byte[]   data_output;
                decrypter.ExtractResource(entry, out data_output);
                current_index++;
                int percent = current_index * 100 / entries_count;
                worker.ReportProgress(percent);
                return(new MemoryStream(data_output));
            };

            encrypter.Save(@"tmo-" + Path.GetFileName(source_file));
        }