2006-03-20 16:43:15 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2010-12-24 04:26:24 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
*
|
2008-01-23 17:25:09 +00:00
|
|
|
* Autosave system:
|
|
|
|
* Saves current mine to disk to prevent loss of work, and support undo.
|
2006-03-20 16:43:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
#include "inferno.h"
|
|
|
|
#include "editor.h"
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "ui.h"
|
2013-03-16 03:10:55 +00:00
|
|
|
#include "strutil.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
#define AUTOSAVE_PERIOD 5 // Number of minutes for timed autosave
|
|
|
|
|
|
|
|
int Autosave_count;
|
2015-12-04 03:36:31 +00:00
|
|
|
static int Autosave_numfiles;
|
|
|
|
static int Autosave_total;
|
|
|
|
static int undo_count;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2015-12-04 03:36:31 +00:00
|
|
|
static int Timer_save_flag;
|
2006-03-20 16:43:15 +00:00
|
|
|
int Autosave_flag;
|
|
|
|
|
2015-04-02 02:36:56 +00:00
|
|
|
array<const char *, 10> undo_status;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
void init_autosave(void) {
|
|
|
|
// int i;
|
|
|
|
|
|
|
|
Autosave_count = 0;
|
|
|
|
Autosave_numfiles = 0;
|
|
|
|
Autosave_flag = 0;
|
|
|
|
undo_count = 0;
|
|
|
|
autosave_mine(mine_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void close_autosave(void) {
|
2013-12-08 05:14:56 +00:00
|
|
|
char *ext;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2014-09-26 02:42:11 +00:00
|
|
|
for (int i=0;i<Autosave_total;i++) {
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2013-12-08 05:14:56 +00:00
|
|
|
char delname[PATH_MAX];
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
strcpy ( delname, mine_filename );
|
2012-05-18 23:36:41 +00:00
|
|
|
d_strupr( delname );
|
2006-03-20 16:43:15 +00:00
|
|
|
if ( !strcmp(delname, "*.MIN") ) strcpy(delname, "TEMP.MIN");
|
|
|
|
|
|
|
|
ext = strstr(delname, ".MIN");
|
2016-01-09 16:38:16 +00:00
|
|
|
snprintf(ext + 2, 3, "%d", i);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
remove( delname );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 22:24:17 +00:00
|
|
|
void autosave_mine(const char *name) {
|
2013-12-08 05:15:27 +00:00
|
|
|
char *ext;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
if (Autosave_flag) {
|
|
|
|
|
2013-12-08 05:15:27 +00:00
|
|
|
char savename[PATH_MAX];
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
strcpy ( savename, name );
|
2012-05-18 23:36:41 +00:00
|
|
|
d_strupr( savename );
|
2006-03-20 16:43:15 +00:00
|
|
|
if ( !strcmp(savename, "*.MIN") ) strcpy(savename, "TEMP.MIN");
|
|
|
|
|
|
|
|
ext = strstr(savename, ".MIN");
|
2016-01-09 16:38:16 +00:00
|
|
|
snprintf(ext + 2, 3, "%d", Autosave_count);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
med_save_mine( savename );
|
|
|
|
Autosave_count++;
|
|
|
|
if (undo_count > 0) undo_count--;
|
|
|
|
if (Autosave_count > 9) Autosave_count -= 10;
|
|
|
|
if (Autosave_numfiles < 10)
|
|
|
|
Autosave_numfiles++;
|
|
|
|
if (Autosave_total < 10)
|
|
|
|
Autosave_total++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-02 02:36:56 +00:00
|
|
|
tm Editor_time_of_day;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2015-04-02 02:36:56 +00:00
|
|
|
static void print_clock()
|
|
|
|
{
|
2015-09-29 02:41:22 +00:00
|
|
|
int w, h;
|
2006-03-20 16:43:15 +00:00
|
|
|
gr_set_current_canvas( NULL );
|
|
|
|
gr_set_fontcolor( CBLACK, CGREY );
|
2015-04-02 02:36:56 +00:00
|
|
|
array<char, 20> message;
|
|
|
|
if (!strftime(message.data(), message.size(), "%m-%d %H:%M:%S", &Editor_time_of_day))
|
|
|
|
message[0] = 0;
|
2015-09-29 02:41:22 +00:00
|
|
|
gr_get_string_size(message.data(), &w, &h, nullptr);
|
2016-02-12 04:02:28 +00:00
|
|
|
const uint8_t color = CGREY;
|
|
|
|
gr_rect( 700, 0, 799, h+1, color);
|
2015-04-02 02:36:56 +00:00
|
|
|
gr_string(700, 0, message.data());
|
2006-03-20 16:43:15 +00:00
|
|
|
gr_set_fontcolor( CBLACK, CWHITE );
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_editor_time_of_day()
|
|
|
|
{
|
|
|
|
time_t ltime;
|
|
|
|
|
|
|
|
time( <ime );
|
|
|
|
Editor_time_of_day = *localtime( <ime );
|
|
|
|
}
|
|
|
|
|
2013-06-08 22:24:17 +00:00
|
|
|
void TimedAutosave(const char *name)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2012-04-09 02:12:58 +00:00
|
|
|
{
|
2015-04-02 02:36:56 +00:00
|
|
|
print_clock();
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef DEMO
|
2015-04-02 02:36:56 +00:00
|
|
|
const auto &minute = Editor_time_of_day.tm_min;
|
2006-03-20 16:43:15 +00:00
|
|
|
if (minute%AUTOSAVE_PERIOD != 0)
|
|
|
|
Timer_save_flag = 1;
|
|
|
|
|
|
|
|
if ((minute%AUTOSAVE_PERIOD == 0) && (Timer_save_flag)) {
|
|
|
|
time_t ltime;
|
|
|
|
|
|
|
|
autosave_mine(name);
|
|
|
|
Timer_save_flag = 0;
|
|
|
|
time( <ime );
|
2013-06-23 22:21:19 +00:00
|
|
|
diagnostic_message_fmt("Mine Autosaved at %s\n", ctime(<ime));
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int undo( void ) {
|
|
|
|
Int3();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:57:24 +00:00
|
|
|
|
|
|
|
}
|