File: loadsave_frame.cc

package info (click to toggle)
simutrans 100.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,776 kB
  • ctags: 9,485
  • sloc: cpp: 72,459; ansic: 5,646; makefile: 450
file content (104 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download
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
/*
 * Copyright (c) 1997 - 2001 Hansjrg Malthaner
 *
 * This file is part of the Simutrans project under the artistic licence.
 * (see licence.txt)
 */

#include "../simdebug.h"

#ifndef _MSC_VER
#include <unistd.h>
#include <dirent.h>
#else
#include <io.h>
#include <direct.h>
#endif
#include <sys/stat.h>
#include <string.h>
#include <time.h>

#include "loadsave_frame.h"

#include "../simworld.h"
#include "../pathes.h"
#include "../utils/simstring.h"


/**
 * Aktion, die nach Knopfdruck gestartet wird.
 * @author Hansjrg Malthaner
 */
void loadsave_frame_t::action(const char *filename)
{
	if(do_load) {
		welt->laden(filename);
	} else {
		welt->speichern(filename,false);
		welt->setze_dirty();
	}
}

void loadsave_frame_t::del_action(const char *filename)
{
	remove(filename);
}


loadsave_frame_t::loadsave_frame_t(karte_t *welt, bool do_load) : savegame_frame_t(".sve",NULL)
{
	this->welt = welt;
	this->do_load = do_load;

	if(do_load) {
		setze_name("Laden");
	} else {
		set_filename(welt->gib_einstellungen()->gib_filename());
		setze_name("Speichern");
	}
}


/**
 * Manche Fenster haben einen Hilfetext assoziiert.
 * @return den Dateinamen fr die Hilfe, oder NULL
 * @author Hj. Malthaner
 */
const char * loadsave_frame_t::gib_hilfe_datei() const
{
	return do_load ? "load.txt" : "save.txt";
}




const char *loadsave_frame_t::get_info(const char *fname)
{
	static char date[1024];
	// first get pak name
	loadsave_t test;
	char path[1024];
	sprintf( path, SAVE_PATH_X "%s", fname );
	test.rd_open(path);
	// then get date
	date[0] = 0;
	struct stat  sb;
	if(stat(path, &sb)==0) {
		// add pak extension
		size_t n = sprintf( date, "%s - ", test.get_pak_extension() );

		// add the time too
		struct tm *tm = localtime(&sb.st_mtime);
		if(tm) {
			strftime(date+n, 18, "%Y-%m-%d %H:%M", tm);
		}
		else {
			tstrncpy(date, "??.??.???? ??:??", 15);
		}
	}
	return date;
}