File changed weird behavior

Post anything you want to discuss with others about the software.

Re: File changed weird behavior

Postby extent » Sat Feb 23, 2019 8:29 pm

you can actually do this quite easily with System.IO.FileSystemEventHandler.

You can see this behavior in visual studio (and really any IDE I can think of) if you have a file open and change it in another program. I do think that blindly reloading is a bad idea (as is holding on to a file lock like mach3 does), and prompting to reload or ignore makes sense, but maybe there is a special case when you've clicked the edit button
extent
 
Posts: 7
Joined: Wed May 24, 2017 11:09 pm

Re: File changed weird behavior

Postby Mark81 » Mon Feb 25, 2019 5:58 pm

I also agree any blind reload is to be avoided, but just a nice message box that tells me the contents has changed and ask id I want to reload. As someone else said, most editors do this, even if the file is actually closed by the application. You might just check the last modified date... it would be enough for this purpose.
Mark81
 
Posts: 42
Joined: Thu Feb 14, 2019 4:38 pm

Re: File changed weird behavior

Postby Dan911 » Mon Feb 25, 2019 8:48 pm

I've gotten a little lost/confused here. How is it a blind reload?

If you load a file in UCCNC than open in editor and make changes in editor and press Save/exit you do get a window warning before reloading and saving file, if no changes are made in editor and press save and exit file is not reloaded because no changes were made.

The slight flaw I see is if the file is changed in another program than reloaded in editor the editor will show these changes but wont save and reload because no changes were made in editor. Simple solution is give window warning and reload file on every save and exit press.
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: File changed weird behavior

Postby Mark81 » Tue Feb 26, 2019 4:54 am

Dan911 wrote:I've gotten a little lost/confused here. How is it a blind reload?


It is when a software reloads a file without asking the user if he really wants to.

The slight flaw I see is if the file is changed in another program than reloaded in editor the editor will show these changes but wont save and reload because no changes were made in editor. Simple solution is give window warning and reload file on every save and exit press.


In my first post, I was talking about a g-code modified by the CAM (so an external program). If you generate (and overwrite) a new version of the g-code currently loaded into UCCNC is not so clear what you actually run. Because:

1. no warnings the file on disk has changed
2. the editor will show the update content
3. but if you don't manually close and open again the file (in RUN window, I haven't tried to press "reload" in TOOLPATH one yet) the g-code is - corretly - the old one

As said, I just kindly asked whether might be useful to warn the user the file has changed and ask him if he would reload it. That's all :lol:
Mark81
 
Posts: 42
Joined: Thu Feb 14, 2019 4:38 pm

Re: File changed weird behavior

Postby dezsoe » Tue Feb 26, 2019 9:42 am

OK, here's a quick solution. :) Save the following macro to a Mxxxx.txt text file in your macro folder (UCCNC\Profiles\Macro_yourprofilename) and set it in macroloops to autorun. If cycle is not started and the file changes then it will ask you to reload the file. If you select NO then it won't ask again until the file changes again. If you change the file while the cycle is started then it will ask only when the code is finished.

Code: Select all
string sFileName = exec.mainform.filenametoload;

if (!exec.GetLED(54) && System.IO.File.Exists(sFileName))                       // Check cycle start and valid file name
{
  if (++counter == 20)                                                          // Check every second
  {
    counter = 0;
    if (sFileName == lastFileName)
    {
      if (lastDateTime != System.IO.File.GetLastWriteTime(lastFileName))
      {
        if (MessageBox.Show("Reload file?", "Loaded file changed!", MessageBoxButtons.YesNo) == DialogResult.Yes)
          exec.Callbutton(555);                                                 // Reload file
        lastDateTime = System.IO.File.GetLastWriteTime(lastFileName);
      }
    }
    else
    {
      lastFileName = sFileName;
      lastDateTime = System.IO.File.GetLastWriteTime(lastFileName);
      // exec.AddStatusmessage("Opened file changed");
    }
  }
}

#Events

string lastFileName = "@";
int counter = 0;
DateTime lastDateTime;
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: File changed weird behavior

Postby Mark81 » Wed Feb 27, 2019 4:30 pm

Great! I will try as soon as possible!
Mark81
 
Posts: 42
Joined: Thu Feb 14, 2019 4:38 pm

Previous

Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: No registered users and 12 guests