NO

Author Topic: Pelles C after lack of energy  (Read 5643 times)

leandrojardim

  • Guest
Pelles C after lack of energy
« on: May 09, 2011, 10:57:50 PM »
After every temporary lack of energy in my country, with the computer on, working on source code with Pelles C, many times I lose the source code that I was editing because Pelles C were holding a lock on the file during the down. When I turn my computer on again, Pelles C asks if I want to recover the backup, but as I cant see if the file was corrupted, the question, at least at that time, is a bit useless, for me.

The result is that many times I lose my work because when I choose to doesnt recover the backup to discover after that the file is corrupted, and then the backup is deleted automatically by Pelles C! And my work is gone... :(
« Last Edit: May 10, 2011, 12:13:54 AM by leandrojardim »

CommonTater

  • Guest
Re: Pelles C after lack of energy
« Reply #1 on: May 10, 2011, 02:30:19 AM »
Wow... that sucks.

In the mean time ... save often.  Type a few lines, save, type a bit more, save...
It's a bit of a pain but it's better than the alternative.

ElectroDoc

  • Guest
Re: Pelles C after lack of energy
« Reply #2 on: May 12, 2011, 09:03:53 AM »
I have the same problem..
Even if you save often, the problem persists. If the power goes down or Windows shut down suddenly, the *opened* source files become corrupted.

I managed this by moving all my programming work to my laptop  ::)

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Pelles C after lack of energy
« Reply #3 on: May 12, 2011, 02:36:35 PM »
A possibility is to check the source file after an energy lack with an normal text editor (the C sources and RC files are plain text files) and if the correct you can start PellesC and keep your files and if they are bad take the backups and hope that they are better than your sources ( if I remember correct Pelle wrote in the help files or the forum where the backups are stored - so you can check them also before).
 
best regards
 Alex ;)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Pelles C after lack of energy
« Reply #4 on: May 12, 2011, 03:29:26 PM »
Look from there:
dir %TEMP%\*.c.*
dir %TEMP%\*.h.*

EDIT:
Insert to Tools menu:
Menu: Tools -> Customize...  -> Tools tab -> New tool

Menu Text: Temp
Command:  cmd.exe
Arguments: /k dir %TEMP%\*.c.* %TEMP%\*.h.*
Use Output Tab
« Last Edit: May 25, 2011, 05:50:53 AM by timovjl »
May the source be with you

MichaelT

  • Guest
Re: Pelles C after lack of energy
« Reply #5 on: May 20, 2011, 02:04:01 PM »
I have to be a bit blunt (no offense) Pelle is not responsible for you having backups. The IDE takes reasonable effort to save your files
but in reality could be completely absent (as is the case with some other compilers) And this is more like a feature
request than anything else. But a bug it is certainly not.

oforshell

  • Guest
Re: Pelles C after lack of energy
« Reply #6 on: May 24, 2011, 08:55:29 PM »
There used to be something in my PC which intermittently caused it to hang, once with POIDE running.

When I restarted the source windows were blank and I was asked if I wanted to restore from backups. I answered no and couldn't find the sources after that. I still don't know if they were lost completely or if they are just lying someplace where I haven't (yet) found them. I got the impression that they were stored in the registry but I'm probably mistaken.

The function may be a good idea which turns sour when exposed to the real world.

CommonTater

  • Guest
Re: Pelles C after lack of energy
« Reply #7 on: May 25, 2011, 03:14:38 AM »
Maybe you should have said "Yes"....

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Pelles C after lack of energy
« Reply #8 on: May 25, 2011, 03:37:19 PM »
Backup Add-In example:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <addin.h>
#include <tchar.h>

// Locals.
static HANDLE g_hmod = NULL;
static HWND g_hwndMain = NULL;

static void BackupFile(HWND hwnd);

BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
g_hmod = hDLL;
return TRUE;
default:
return TRUE;
}
}

ADDINAPI BOOL WINAPI AddInMain(HWND hwnd, ADDIN_EVENT eEvent)
{
switch (eEvent)
{
case AIE_APP_CREATE:
/* Save handle of main window */
g_hwndMain = hwnd;
return TRUE;
case AIE_DOC_SAVE:
BackupFile(hwnd);
return TRUE;
default:
return TRUE;
}
}

static void BackupFile(HWND hwnd)
{
ADDIN_DOCUMENT_INFO DocInfo = {0};

DocInfo.cbSize = sizeof(DocInfo);
if (AddIn_GetDocumentInfo(hwnd, &DocInfo))
{
TCHAR buf[512];
if (*DocInfo.szFilename) {
wsprintf(buf, _T("%s.bak"), DocInfo.szFilename);
CopyFile(DocInfo.szFilename, buf, FALSE);
//AddIn_WriteOutput(g_hwndMain, buf);
}
}
}
May the source be with you

CommonTater

  • Guest
Re: Pelles C after lack of energy
« Reply #9 on: May 26, 2011, 04:09:46 AM »
If you look in the POIDE Tools->Options->General tab there is an option to make backups of your source files.  It will make a backup each time you save, so your greatest loss is since your last save...


leandrojardim

  • Guest
Re: Pelles C after lack of energy
« Reply #10 on: June 28, 2011, 01:41:48 AM »
I have to be a bit blunt (no offense) Pelle is not responsible for you having backups. The IDE takes reasonable effort to save your files
but in reality could be completely absent (as is the case with some other compilers) And this is more like a feature
request than anything else. But a bug it is certainly not.

You said one true thing, its more or less a feature request. ;) Sorry...

But when Pelles C is running, it never saves completely the file that us are working on. Looks like the file is write, but at the same time is hold some type of lock, maybe its a memory mapped file, I dont know.

For example, it could be that, when Pelles C crashes or in the event of a loss of energy, the cache used by Windows cannot be flushed and the file gets corrupt, probably because of the file being memory mapped.

If its the problem, computers today with Windows 7 are fast and have plenty of memory, maybe could be a good idea to load the file completely to the memory, or better load and write it in pieces, simulating a memory mapped file (not in the strict sense).

All your points are very, very true, but the need to use always the backup to recover files is not a good thing also, in terms of what is correct or not (the best option, lets say).

But its a very good feature, and its validity is not hidden completely by us doing backups, like could look.

But I understand everything. :)
« Last Edit: June 28, 2011, 02:11:30 AM by leandrojardim »

Gary Willoughby

  • Guest
Re: Pelles C after lack of energy
« Reply #11 on: June 30, 2011, 07:42:04 PM »
Use source control such as Mercurial

leandrojardim

  • Guest
Re: Pelles C after lack of energy
« Reply #12 on: July 08, 2011, 12:09:48 AM »
Thanks, I will use it! Now looking at it, it is what I always needed for a loong time! :)
« Last Edit: July 08, 2011, 12:12:21 AM by leandrojardim »