Fix network files hanging while the network disconnected (part 2)
Refactoring for reducing the I/O calls, fix typos.
Reduce the startup time (while the a dirty disconnected network file is in the session) from about 12-15 seconds to about 6 seconds (on my laptop).
Note that there are 2 cases are not improved by the commit:
* STR 1: Open a network file, modify it. Disconnect the network, then save the file.
There will be a huge hanging time (around 1 minute) to get the warning dialog.
I tried to remedy with thread for CreateFileW in the constructor of Win32_IO_File, however it leads crash due to the lock guard in the caller.
* STR 2:
1. Open a network file.
2. Close Notepad++ to have it in the session.
3. Disconnect the network, and launch Notepad++ immediately.
4. Around more than 1 minute's delay, then the "Error" dialog displayed.
The reason of hanging is that the network file was detected by "doesFileExist" as true, so Notepad++ was trying to open non-existent file (by _wfopen).
I believe that there's some kind of cache during the very short period for the IO function (here's our case GetFileAttributes), and such cache is not immediately synchronized (cleared) while network disconnected. As a result, when we launch Notepad++ after the disconnection of network, GetFileAttributes keeps its memory & responds "FileExists". However for _wfopen it doesn't see the resource of network anymore - that makes hanging.
Ref #15658
Improve #4306, #6178, #8055, #11388, #12553, #15540Close#15669
_hFile=::CreateFileW(fname,_accessParam,_shareParam,NULL,dispParam,_attribParam,NULL);// No thread (CreateFileWaitSec) due to the lock guard in the caller which leads crash
// Race condition management:
// If file didn't exist while calling PathFileExistsW, but before calling CreateFileW, file is created: use CREATE_ALWAYS is OK
{L"Mark Zuckerberg",QuoteParams::slow,false,SC_CP_UTF8,L_TEXT,L"\"Black lives matter\" doesn't mean other lives don't - it's simply asking that the black community also achieves the justice they deserve."},
{L"Michael Feldman",QuoteParams::slow,false,SC_CP_UTF8,L_TEXT,L"Java is, in many ways, C++--."},
{L"Don Ho",QuoteParams::slow,false,SC_CP_UTF8,L_TEXT,L"Je mange donc je chie."},
{L"Don Ho #2",QuoteParams::rapid,true,SC_CP_UTF8,L_TEXT,L"RTFM is the true path of every developer.\nBut it would happen only if there's no way out."},
{L"Don Ho #3",QuoteParams::rapid,true,SC_CP_UTF8,L_TEXT,L"The smartphone is the best invention of the 21st century for avoiding eye contact with people you know while crossing the street."},
{L"Don Ho #4",QuoteParams::rapid,false,SC_CP_UTF8,L_TEXT,L"Poor countries' museums vs. rich countries' museums:\nThe first show what they have left.\nThe second show what they have stolen."},
{L"Don Ho #2",QuoteParams::rapid,true,SC_CP_UTF8,L_TEXT,L"RTFM is the true path for every developer.\nHowever, it only happens when there's no other way out."},
{L"Don Ho #3",QuoteParams::rapid,true,SC_CP_UTF8,L_TEXT,L"The smartphone is the best invention of the 21st century for avoiding eye contact with acquaintances while crossing the street."},
{L"Don Ho #4",QuoteParams::rapid,false,SC_CP_UTF8,L_TEXT,L"Museums in poor countries vs. museums in rich countries:\nThe former display what they have left.\nThe latter display what they have taken."},
{L"Don Ho #5",QuoteParams::slow,false,SC_CP_UTF8,L_TEXT,L"With great refactoring comes great regressions."},
{L"Don Ho #6",QuoteParams::rapid,false,SC_CP_UTF8,L_TEXT,L"Naming a variable always reminds me the effort I put into my existence,\nfor giving some sense to my meaningless life."},
{L"Don Ho #6",QuoteParams::rapid,false,SC_CP_UTF8,L_TEXT,L"Naming a variable always reminds me of the effort I put into my existence,\nfor giving some sense to my meaningless life."},
{L"Anonymous #1",QuoteParams::slow,false,SC_CP_UTF8,L_TEXT,L"An opinion without 3.14 is just an onion."},
{L"Anonymous #2",QuoteParams::rapid,true,SC_CP_UTF8,L_TEXT,L"Before sex, you help each other get naked, after sex you only dress yourself.\nMoral of the story: in life no one helps you once you're fucked."},
{L"Anonymous #3",QuoteParams::rapid,false,SC_CP_UTF8,L_TEXT,L"I'm not totally useless. I can be used as a bad example."},