-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (65 loc) · 2.62 KB
/
Program.cs
File metadata and controls
73 lines (65 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace MultiPNGToHAR
{
internal class Program
{
private static readonly List<byte> _header = new List<byte>
{
0x48, 0x41, 0x52, 0x43
};
private static string _file;
private static int _fileCount;
public static void Main(string[] args)
{
Console.WriteLine(
"Input path containing PNG Files sorted by numerical value according to original HAR file.");
var _pathToPNGs = Console.ReadLine();
if (Directory.Exists(_pathToPNGs))
{
var files = Directory.GetFiles(_pathToPNGs, "*.png");
var maxlen = files.Max(x => x.Length);
var sortedFiles = files.OrderBy(x => x.PadLeft(maxlen, '0'));
var _pngBytes = new List<byte>();
foreach (var file in sortedFiles)
{
var reader = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.ReadWrite));
reader.BaseStream.Position = 0x00;
_pngBytes.AddRange(reader.ReadBytes((int) reader.BaseStream.Length).ToList());
_fileCount++;
reader.Close();
}
_file = Directory.GetCurrentDirectory() + @"\New.har";
_pngBytes.Add(0x82);
File.WriteAllBytes(_file, _pngBytes.ToArray());
var newFile = ComputeInfo();
newFile.AddRange(_pngBytes);
File.Delete(_file);
File.WriteAllBytes(_file, newFile.ToArray());
Console.WriteLine("Complete, Press any key to exit.");
Console.ReadKey();
}
else
{
Console.WriteLine("ERROR! Could not find path! Please make sure you have inputted path correctly!");
Console.ReadKey();
}
}
public static List<byte> ComputeInfo()
{
var combinedHeader = _header;
var currentFile = new FileInfo(_file);
var fileSize = currentFile.Length;
var fileSizeArr = BitConverter.GetBytes(fileSize).ToList();
fileSizeArr.RemoveRange(4, fileSizeArr.Count() - 4);
var fileCountArr = BitConverter.GetBytes(_fileCount).ToList();
fileCountArr.RemoveRange(4, fileCountArr.Count() - 4);
combinedHeader.AddRange(fileCountArr);
combinedHeader.AddRange(fileSizeArr);
return combinedHeader;
}
}
}