Skip to content

Commit

Permalink
Split tmp payload path
Browse files Browse the repository at this point in the history
* To make sure payload dumper and fastboot flasher can work at the same time
  • Loading branch information
libxzr committed Sep 5, 2021
1 parent 7a48b45 commit ed639a5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion FastbootUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace FastbootEnhance
{
class FastbootUI
{
public const string PAYLOAD_TMP = ".\\payload.tmp.fastboot";
static List<fastboot_devices_row> devices;
static string cur_serial;
static FastbootData fastbootData;
Expand Down Expand Up @@ -668,7 +669,7 @@ public static void init()
{
try
{
payload = new Payload(path);
payload = new Payload(path, PAYLOAD_TMP);
}
catch (Exception e)
{
Expand Down
19 changes: 17 additions & 2 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public MainWindow()

try
{
new DirectoryInfo(Payload.PAYLOAD_TMP).Delete(true);
new DirectoryInfo(PayloadUI.PAYLOAD_TMP).Delete(true);
}
catch (DirectoryNotFoundException) { }

try
{
new DirectoryInfo(FastbootUI.PAYLOAD_TMP).Delete(true);
}
catch (DirectoryNotFoundException) { }

Expand All @@ -31,12 +37,21 @@ public MainWindow()
{
if (PayloadUI.payload != null)
PayloadUI.payload.Dispose();

try
{
new DirectoryInfo(Payload.PAYLOAD_TMP).Delete(true);
new DirectoryInfo(PayloadUI.PAYLOAD_TMP).Delete(true);
}
catch (DirectoryNotFoundException) { }
catch (IOException) { }

try
{
new DirectoryInfo(FastbootUI.PAYLOAD_TMP).Delete(true);
}
catch (DirectoryNotFoundException) { }
catch (IOException) { }

Process.GetCurrentProcess().Kill();
};
}
Expand Down
12 changes: 7 additions & 5 deletions Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace FastbootEnhance
{
public class Payload : IDisposable
{
public const string PAYLOAD_TMP = ".\\payload.tmp";
string payload_tmp;
BinaryReader binaryReader;
public class PayloadInitException : Exception
{
Expand Down Expand Up @@ -191,24 +191,26 @@ public void Dispose()
}
try
{
new DirectoryInfo(PAYLOAD_TMP).Delete(true);
new DirectoryInfo(payload_tmp).Delete(true);
}
catch (DirectoryNotFoundException) { }
catch (IOException) { }
}

public Payload(string path)
public Payload(string path, String tmpdir)
{
payload_tmp = tmpdir;

if (path.EndsWith(".zip"))
{
ZipFile zip = new ZipFile(path);
foreach (ZipEntry entry in zip.Entries)
{
if (entry.FileName == "payload.bin")
{
entry.Extract(PAYLOAD_TMP);
entry.Extract(payload_tmp);
binaryReader = new BinaryReader(
new FileStream(PAYLOAD_TMP + "\\payload.bin", FileMode.Open));
new FileStream(payload_tmp + "\\payload.bin", FileMode.Open));
return;
}
}
Expand Down
4 changes: 3 additions & 1 deletion PayloadUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace FastbootEnhance
{
class PayloadUI
{
public const string PAYLOAD_TMP = ".\\payload.tmp.dumper";

enum page_status
{
empty,
Expand Down Expand Up @@ -42,7 +44,7 @@ static void onLoad(string filename)
{
try
{
payload = new Payload(filename);
payload = new Payload(filename, PAYLOAD_TMP);
}
catch (Exception e)
{
Expand Down

0 comments on commit ed639a5

Please sign in to comment.