| 289 | } |
| 290 | |
| 291 | bool CHexMergeDoc::DoFileSave(int nBuffer) |
| 292 | { |
| 293 | bool result = false; |
| 294 | if (m_pView[nBuffer]->GetModified()) |
| 295 | { |
| 296 | if (m_nBufferType[nBuffer] == BUFFERTYPE::UNNAMED) |
| 297 | result = DoFileSaveAs(nBuffer); |
| 298 | else |
| 299 | { |
| 300 | String strSavePath = m_strSaveAsPath.empty() ? m_filePaths.GetPath(nBuffer) : m_strSaveAsPath; |
| 301 | // Warn user in case file has been changed by someone else |
| 302 | if (m_pView[nBuffer]->IsFileChangedOnDisk(m_filePaths.GetPath(nBuffer).c_str()) == IMergeDoc::FileChange::Changed) |
| 303 | { |
| 304 | String msg = strutils::format_string1(_("Another application updated\n%1\nsince WinMerge loaded it.\n\nOverwrite?"), m_filePaths.GetPath(nBuffer)); |
| 305 | if (AfxMessageBox(msg.c_str(), MB_ICONWARNING | MB_YESNO) == IDNO) |
| 306 | return false; |
| 307 | } |
| 308 | // Ask user what to do about FILE_ATTRIBUTE_READONLY |
| 309 | String strPath = strSavePath; |
| 310 | bool bApplyToAll = false; |
| 311 | if (CMergeApp::HandleReadonlySave(strPath, false, bApplyToAll) == IDCANCEL) |
| 312 | return false; |
| 313 | strSavePath = strPath.c_str(); |
| 314 | // Take a chance to create a backup |
| 315 | if (!CMergeApp::CreateBackup(false, strSavePath)) |
| 316 | return false; |
| 317 | HRESULT hr = m_pView[nBuffer]->SaveFile(strSavePath.c_str()); |
| 318 | if (Try(hr) == IDCANCEL) |
| 319 | return false; |
| 320 | if (FAILED(hr)) |
| 321 | return DoFileSaveAs(nBuffer); |
| 322 | result = true; |
| 323 | if (result) |
| 324 | { |
| 325 | m_filePaths[nBuffer] = strSavePath; |
| 326 | UpdateHeaderPath(nBuffer); |
| 327 | int compareResult = UpdateLastCompareResult(); |
| 328 | // If directory compare has results |
| 329 | if (m_pDirDoc != nullptr && m_pDirDoc->HasDiffs()) |
| 330 | { |
| 331 | m_pDirDoc->UpdateChangedItem(m_filePaths, |
| 332 | static_cast<unsigned>(-1), static_cast<unsigned>(-1), |
| 333 | compareResult == 0); |
| 334 | } |
| 335 | |
| 336 | CMergeFrameCommon::LogFileSaved(m_filePaths[nBuffer]); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | return result; |
| 341 | } |
| 342 | |
| 343 | bool CHexMergeDoc::DoFileSaveAs(int nBuffer, bool packing) |
| 344 | { |
nothing calls this directly
no test coverage detected