
#ifndef SESSION_H
#define SESSION_H

/*
 * @(#)Session.h
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 1999-2002 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDWserver.cpp for details.
 */

#include <stdio.h>
#include "File.h"

class Server;
class MP3toWAV;

class Session
{
	Server *server;
	const char *ID;
	File *dir;
	File *currentTrack;
	int currentTrackNo;
	int filesNum, tracksNum, sizeInKBytes;
	MP3toWAV *mp3towav;

public:
	~Session();
	File *getFirstTrack();
	int getFilesNum() { return filesNum; }
	const char *getID() { return ID; }
	static void getInfo(const char *ID,
		int &numOfFiles, int &numOfTracks, int &size_KB);
	File *getNextTrack();
	Server *getServer() { return server; }
	static int getSessionSize(File &dir);
	unsigned long getSize() { return 1024 * sizeInKBytes; }
	int getTracksNum() { return tracksNum; }
	static int isSessionDir(File &dir);
	void linkFile(const char *fileName, const char *linkName);
	void linkTrack(const char *name, const char *type);
	void makeDir(const char *fileName, int mode, int time);
	void newTrack(const char *trackType);
	void putFile(FILE *inStream,
		const char *fileName, int length, int mode, int time);
	void putTrack(FILE *inStream, int length);

private:
	Session(Server *server, const char *ID, const char *dir);
	void closeMP3Track();
	void copy(FILE *inStream, FILE *outStream, int length);
	void copy(const char *buf, FILE *outStream, int length);
	void copy2(FILE *inStream, FILE *outStream, int &length);
	void countFile(const char *pathName);
	void create();
	void readInfo();
	static void readInfo(File *dir,
		int &numOfFiles, int &numOfTracks, int &size_KB);
	static int sizeToKBytes(int size);
	void writeInfo();

	friend class Store;
};

#endif
