Skip to content

Commit 3699bdb

Browse files
committed
2 parents 52aec6d + ef644d8 commit 3699bdb

7 files changed

Lines changed: 97 additions & 60 deletions

File tree

csharp/Plugins/Gjgj/Plugin.Gjgj.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
</StartupObject>
3939
</PropertyGroup>
4040
<ItemGroup>
41-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
42-
<SpecificVersion>False</SpecificVersion>
43-
<HintPath>..\..\..\..\..\..\..\..\软件\编曲\合成器\X Studio 2.0.2\XStudioSinger\Newtonsoft.Json.dll</HintPath>
41+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
42+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
4443
</Reference>
4544
<Reference Include="System" />
4645
<Reference Include="System.Core" />
@@ -62,6 +61,7 @@
6261
</ItemGroup>
6362
<ItemGroup>
6463
<None Include="App.config" />
64+
<None Include="packages.config" />
6565
</ItemGroup>
6666
<ItemGroup>
6767
<ProjectReference Include="..\..\Framework\OpenSvip.Framework.csproj">
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
4+
</packages>

csharp/Plugins/Vogen/Plugin.Vogen.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
</PropertyGroup>
3333
<ItemGroup>
3434
<Reference Include="ICSharpCode.SharpZipLib, Version=0.85.4.369, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
35-
<HintPath>..\packages\ICSharpCode.SharpZipLib.dll.0.85.4.369\lib\net20\ICSharpCode.SharpZipLib.dll</HintPath>
35+
<HintPath>..\..\packages\ICSharpCode.SharpZipLib.dll.0.85.4.369\lib\net20\ICSharpCode.SharpZipLib.dll</HintPath>
3636
</Reference>
37-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
38-
<SpecificVersion>False</SpecificVersion>
39-
<HintPath>..\..\..\..\..\..\..\软件\编曲\合成器\X Studio 2.0.2\XStudioSinger\Newtonsoft.Json.dll</HintPath>
37+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
38+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
4039
</Reference>
4140
<Reference Include="System" />
4241
<Reference Include="System.Core" />
@@ -53,6 +52,7 @@
5352
<Compile Include="VogenDecoder.cs" />
5453
<Compile Include="VogenEncoder.cs" />
5554
<Compile Include="VogenModel.cs" />
55+
<Compile Include="ZipHelper.cs" />
5656
</ItemGroup>
5757
<ItemGroup>
5858
<ProjectReference Include="..\..\Framework\OpenSvip.Framework.csproj">

csharp/Plugins/Vogen/Properties.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Plugin>
33
<Name>Vogen</Name>
4-
<Version>0.1.0</Version>
4+
<Version>0.2.0</Version>
55
<Author>笛鹿FlutyDeer</Author>
66
<HomePage>https://space.bilibili.com/386270936</HomePage>
77
<Descriptions>Vogen 工程格式转换插件。</Descriptions>
Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Text;
34
using Newtonsoft.Json;
45
using OpenSvip.Framework;
56
using OpenSvip.Model;
6-
using System;
77
using Plugin.Vogen;
88
using Vogen.Model;
9-
using ICSharpCode.SharpZipLib.Zip;
109

1110
namespace 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
}

csharp/Plugins/Vogen/ZipHelper.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using ICSharpCode.SharpZipLib.Zip;
2+
using System;
3+
using System.IO;
4+
5+
namespace Plugin.Vogen
6+
{
7+
public static class ZipHelper
8+
{
9+
//压缩文件
10+
public static void CompressFile(string filePath, string zipPath)
11+
{
12+
using (ZipOutputStream s = new ZipOutputStream(File.Create(zipPath)))
13+
{
14+
s.SetLevel(9);
15+
byte[] buffer = new byte[4096];
16+
ZipEntry entry = new ZipEntry(Path.GetFileName(filePath));
17+
entry.DateTime = DateTime.Now;
18+
s.PutNextEntry(entry);
19+
using (FileStream fs = File.OpenRead(filePath))
20+
{
21+
int sourceBytes;
22+
do
23+
{
24+
sourceBytes = fs.Read(buffer, 0, buffer.Length);
25+
s.Write(buffer, 0, sourceBytes);
26+
} while (sourceBytes > 0);
27+
}
28+
s.Finish();
29+
s.Close();
30+
}
31+
}
32+
33+
//解压文件
34+
public static void DecompressFile(string sourceFile, string targetPath)
35+
{
36+
if (!File.Exists(sourceFile))
37+
{
38+
throw new FileNotFoundException(string.Format("未能找到文件 '{0}' ", sourceFile));
39+
}
40+
if (!Directory.Exists(targetPath))
41+
{
42+
Directory.CreateDirectory(targetPath);
43+
}
44+
using (var s = new ZipInputStream(File.OpenRead(sourceFile)))
45+
{
46+
ZipEntry theEntry;
47+
while ((theEntry = s.GetNextEntry()) != null)
48+
{
49+
if (theEntry.IsDirectory)
50+
{
51+
continue;
52+
}
53+
string directorName = Path.Combine(targetPath, Path.GetDirectoryName(theEntry.Name));
54+
string fileName = Path.Combine(directorName, Path.GetFileName(theEntry.Name));
55+
if (!Directory.Exists(directorName))
56+
{
57+
Directory.CreateDirectory(directorName);
58+
}
59+
if (!String.IsNullOrEmpty(fileName))
60+
{
61+
using (FileStream streamWriter = File.Create(fileName))
62+
{
63+
int size = 4096;
64+
byte[] data = new byte[size];
65+
while (size > 0)
66+
{
67+
streamWriter.Write(data, 0, size);
68+
size = s.Read(data, 0, data.Length);
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="ICSharpCode.SharpZipLib.dll" version="0.85.4.369" targetFramework="net472" />
4+
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
45
</packages>

0 commit comments

Comments
 (0)