Skip to content

Commit

Permalink
🐞 fix: 修正中文无法创建日历问题
Browse files Browse the repository at this point in the history
  • Loading branch information
imlinhanchao committed May 21, 2024
1 parent a4e6195 commit 2ee7fef
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Notes/app/Note.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Note.h"
#include <locale>

CNote::CNote()
{
Expand Down Expand Up @@ -129,6 +130,8 @@ void CNote::MakeTask(NoteItem item)
CStdioFile file;
CString sPath = Path::GetTmpDirectory(Cvt::ToString(CTime(GetCurrentTime()), _T("%Y%m%d%H%M%S")) + _T(".ics"));
if (!file.Open(sPath, CFile::modeCreate | CFile::modeWrite)) return;
char* old_locale = _strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "chs");//É趨
CString icsTpl = _T("BEGIN:VCALENDAR\n\
VERSION:2.0\n\
PRODID:-//Hancel.Lin//StickyNotes//EN\n\
Expand All @@ -149,6 +152,10 @@ END:VCALENDAR");
icsTpl.Replace(_T("{SUMMARY}"), item.sContent);
icsTpl.Replace(_T("{DESCRIPTION}"), item.sContent);
file.WriteString(icsTpl);

setlocale(LC_ALL, old_locale);//»¹Ô­
free(old_locale);

file.Close();

ShellExecute(NULL, _T("open"), sPath, NULL, NULL, SW_SHOWNORMAL);
Expand Down

0 comments on commit 2ee7fef

Please sign in to comment.