-
내일배움캠프 27일차 TIL - C# FileStream 써보기Misc/오늘 알아낸 것 2023. 9. 3. 23:25
오늘은 리소스를 추출하고 싶어서 깃헙에 돌아다니다가
외국인 프로젝트를 받았는데 사용법이 안적혀있어서 깃헙에 검색해보고
중국인이 사용한 프로젝트가 있길래 다운 받고 이러면서 시간을 보냈다...
기본적이긴하지만 해당 작업을 시작할때 가장 처음 막혔던거를 적어둔다..
string filePath = System.IO.Directory.GetCurrentDirectory() + "/File.PAK"; using (FileStream fileStream = new FileStream(filePath, FileMode.Open)) { Entry[] unpackedData = PAKManager.Unpack(fileStream); string outputFilePath = System.IO.Directory.GetCurrentDirectory() + "/output"; for (int i = 0; i < unpackedData.Length; i++) { using (FileStream outputFileStream = new FileStream(outputFilePath + i.ToString(), FileMode.Create)) { using (StreamWriter writer = new StreamWriter(outputFileStream)) { writer.Write(unpackedData[i].Content); writer.Close(); } outputFileStream.Close(); } } fileStream.Close(); }
씨샵으로 파일 쓰기 읽기를 안해봐서 막혔었다
FileStream 클래스를 초기화 할때 FileMode 매개변수에 따라 용도에 따른 스트림을 초기화 할 수 있다
FileMode.Open은 파일을 읽는 용도
FileMode.Create는 파일을 생성 할 수 있다
StreamWriter 클래스는 스트림을 받아서 쓰는 역할을 한다
그리고 이런 클래스들은 당연하지만 한번 열었으면 닫아줘야한다
일단 위에 코드 설명하자면 해당 파일을 읽어와서 복호화 작업을 한 다음에 잘라낸 스트림을
배열로 받아서 파일을 생성하는 코드이다
복호화하는 부분을 보았는데 25 바이트로 자르고 어떤 기준으로 합쳐서 쓰는지 적혀있지 않았기 때문에
제대로 된 파일이 나오지 않았다
public struct PAKHeader { public uint HeaderLength; public uint FileCount; uint Unk1;//Flags? public uint BlockSize; uint Unk2; uint Unk3; uint Unk4; uint Unk5; public uint Flags; //More Random Unk Data, I will Ignore. } public struct Entry { public uint Offset; public uint Length; [Ignore] public Stream Content; [Ignore] public string FileName; }
이 프로젝트를 만든 사람이 PakHeader와 Entry라는 구조체를 만들어놓았는데
안에 속성을 이용하면 될거같다
정답에 근접한거같은데 해결할수있을까
'Misc > 오늘 알아낸 것' 카테고리의 다른 글
내일배움캠프 30일차 TIL - 오늘은 캐릭터 기획을 했다 (0) 2023.09.06 내일배움캠프 28일차 TIL - 깃헙에서 중국인 라이브러리 가져와서 써보기 (0) 2023.09.04 내일배움캠프 25일차 TIL - 콘솔 RPG 팀 프로젝트 완성 (0) 2023.09.01 내일배움캠프 24일차 TIL - 팀으로 콘솔 텍스트 RPG 만들기 제출 하루 전 (0) 2023.08.31 내일배움캠프 23일차 TIL - 팀으로 콘솔 텍스트 RPG 만들기 3 (0) 2023.08.30