-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,104 additions
and
726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* GNU AFFERO GENERAL PUBLIC LICENSE | ||
* Version 3, 19 November 2007 | ||
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
namespace PrusaSL1Reader.Extensions | ||
{ | ||
public static class ZipArchiveExtensions | ||
{ | ||
/// <summary> | ||
/// Create a file into archive and write content to it | ||
/// </summary> | ||
/// <param name="input"><see cref="ZipArchive"/></param> | ||
/// <param name="filename">Filename to create</param> | ||
/// <param name="content">Content to write</param> | ||
/// <returns>Created <see cref="ZipArchiveEntry"/></returns> | ||
public static ZipArchiveEntry PutFileContent(this ZipArchive input, string filename, string content, bool deleteFirst = true) | ||
{ | ||
if(deleteFirst) input.GetEntry(filename)?.Delete(); | ||
|
||
var entry = input.CreateEntry(filename); | ||
if (ReferenceEquals(content, null)) return entry; | ||
using (TextWriter tw = new StreamWriter(entry.Open())) | ||
{ | ||
tw.Write(content); | ||
tw.Close(); | ||
} | ||
|
||
return entry; | ||
} | ||
|
||
public static ZipArchiveEntry PutFileContent(this ZipArchive input, string filename, Stream content, bool deleteFirst = true) | ||
{ | ||
if (deleteFirst) input.GetEntry(filename)?.Delete(); | ||
var entry = input.CreateEntry(filename); | ||
if (ReferenceEquals(content, null)) return entry; | ||
using (StreamWriter tw = new StreamWriter(entry.Open())) | ||
{ | ||
tw.Write(content); | ||
tw.Close(); | ||
} | ||
|
||
return entry; | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.