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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace PLAEditor
{
class PLAEngine
{
StreamReader stream;
BinaryReader reader;
bool loaded;
List<string> songs;
string rootDir = "";
public PLAEngine(string filePath)
{
stream = new StreamReader(filePath);
reader = new BinaryReader(stream.BaseStream);
// Пропускаем хидер, ибо там полезной инфы - 0
reader.BaseStream.Position += 512;
loaded = false;
songs = new List<string>();
LoadSongs();
}
private void LoadSongs()
{
try
{
Int64 length = reader.BaseStream.Length;
while (reader.BaseStream.Position < length)
{
reader.BaseStream.Position += 2;
byte[] songArray = reader.ReadBytes(510);
Encoding encodingA = System.Text.Encoding.GetEncoding(1251);
Encoding encodingU = System.Text.Encoding.BigEndianUnicode;
byte[] songArrayA = Encoding.Convert(encodingU, encodingA, songArray);
string fileName = encodingA.GetString(songArrayA);
if (songs.Count > 1320)
{
this.loaded = true;
}
int dirEnd = fileName.LastIndexOf(@"\");
if (dirEnd > 0)
{
string dirPath = fileName.Substring(0, dirEnd);
FindRootDir(dirPath);
}
songs.Add(fileName);
}
this.loaded = true;
}
catch(Exception ex)
{
this.loaded = false;
}
RemoveRootDir();
}
private void FindRootDir(string dir)
{
if ((rootDir.Length != 0) && (dir.Length != 0) && (dir[0] != rootDir[0]))
return;
else if (rootDir.Length == 0)
rootDir = dir;
string tmpLast = "";
int length = Math.Min(dir.Length, rootDir.Length);
for (int i = 0; i < length; i++)
{
if (dir[i].Equals(rootDir[i]))
{
tmpLast += dir[i];
}
}
rootDir = tmpLast;
}
private void RemoveRootDir()
{
//rootDir = rootDir.Substring(0, rootDir.Length - 1);
if (rootDir.Length == 0)
return;
for(int i = 0; i < songs.Count; i++)
{
songs[i] = songs[i].Replace(rootDir, "");
}
}
public byte[] Int16ToBigEndian(Int16 value)
{
return new byte[0x2] {
(byte) (value >> 0x8),
(byte) (value)
};
}
// Не надо :)
// Серьёзно. Зачем мне этот DirStart?
/*
public Int16 BigEndianToInt16(byte[] value)
{
return BitConverter.ToInt16(new byte[0x2] { value[1], value[0] }, 0);
}
*/
public bool Loaded
{
get { return loaded; }
}
public List<string> Songs
{
get { return songs; }
}
public string RootDir
{
get { return rootDir; }
}
}
}