1- using System . IO ;
1+ using System ;
2+ using System . IO ;
23using System . Text ;
34using Newtonsoft . Json ;
45using OpenSvip . Framework ;
56using OpenSvip . Model ;
6- using System ;
77using Plugin . Vogen ;
88using Vogen . Model ;
9- using ICSharpCode . SharpZipLib . Zip ;
109
1110namespace Vogen . Stream
1211{
@@ -15,12 +14,15 @@ internal class VogenConverter : IProjectConverter
1514
1615 public Project Load ( string path , ConverterOptions options )
1716 {
18- var stream = new FileStream ( path , FileMode . Open , FileAccess . Read ) ;
17+ ZipHelper . DecompressFile ( path , Path . GetDirectoryName ( path ) ) ;
18+ string chartJsonPath = Path . GetDirectoryName ( path ) + "\\ " + "chart.json" ;
19+ var stream = new FileStream ( chartJsonPath , FileMode . Open , FileAccess . Read ) ;
1920 var reader = new StreamReader ( stream , Encoding . UTF8 ) ;
2021 var vogenProject = JsonConvert . DeserializeObject < VogenProject > ( reader . ReadToEnd ( ) ) ;
2122 stream . Close ( ) ;
2223 reader . Close ( ) ;
2324 return new VogenDecoder ( ) . DecodeProject ( vogenProject ) ;
25+ //return new Project();
2426 }
2527
2628 public void Save ( string path , Project project , ConverterOptions options )
@@ -40,55 +42,9 @@ public void Save(string path, Project project, ConverterOptions options)
4042 string chartJsonPath = Path . GetDirectoryName ( path ) + "\\ " + "chart.json" ;
4143 FileInfo fi = new FileInfo ( path ) ;
4244 fi . MoveTo ( chartJsonPath ) ;
43- ZipFile ( chartJsonPath , Path . GetDirectoryName ( path ) + "\\ " + Path . GetFileNameWithoutExtension ( path ) + ".vog" ) ;
45+ ZipHelper . CompressFile ( chartJsonPath , Path . GetDirectoryName ( path ) + "\\ " + Path . GetFileNameWithoutExtension ( path ) + ".vog" ) ;
4446 File . Delete ( chartJsonPath ) ;
4547 }
46-
47- /// <summary>
48- /// 单文件压缩
49- /// </summary>
50- /// <param name="sourceFile">源文件</param>
51- /// <param name="zipedFile">zip压缩文件</param>
52- /// <param name="blockSize">缓冲区大小</param>
53- /// <param name="compressionLevel">压缩级别</param>
54- public static void ZipFile ( string sourceFile , string zipedFile , int blockSize = 1024 , int compressionLevel = 6 )
55- {
56- if ( ! File . Exists ( sourceFile ) )
57- {
58- throw new System . IO . FileNotFoundException ( "The specified file " + sourceFile + " could not be found." ) ;
59- }
60- var fileName = System . IO . Path . GetFileName ( sourceFile ) ;
61-
62- FileStream streamToZip = new FileStream ( sourceFile , FileMode . Open , FileAccess . Read ) ;
63- FileStream zipFile = File . Create ( zipedFile ) ;
64- ZipOutputStream zipStream = new ZipOutputStream ( zipFile ) ;
65-
66- ZipEntry zipEntry = new ZipEntry ( fileName ) ;
67- zipStream . PutNextEntry ( zipEntry ) ;
68-
69- //存储、最快、较快、标准、较好、最好 0-9
70- zipStream . SetLevel ( compressionLevel ) ;
71-
72- byte [ ] buffer = new byte [ blockSize ] ;
73-
74- int size = streamToZip . Read ( buffer , 0 , buffer . Length ) ;
75- zipStream . Write ( buffer , 0 , size ) ;
76- try
77- {
78- while ( size < streamToZip . Length )
79- {
80- int sizeRead = streamToZip . Read ( buffer , 0 , buffer . Length ) ;
81- zipStream . Write ( buffer , 0 , sizeRead ) ;
82- size += sizeRead ;
83- }
84- }
85- catch ( Exception ex )
86- {
87- throw ex ;
88- }
89- zipStream . Finish ( ) ;
90- zipStream . Close ( ) ;
91- streamToZip . Close ( ) ;
92- }
48+
9349 }
9450}
0 commit comments