Example #1
0
void
MoonInstallerService::UpdaterCompleted ()
{
	char *content, *path, *tmp;
	char *xap;
	int err = 0;
	gsize size;
	gsize xap_len;
	FILE *fp;
	
	path = g_build_filename (GetBaseInstallDir (), app->uid, "Application.xap", NULL);
	
	// check that the xap has changed...
	if (g_file_get_contents (path, &content, &size, NULL)) {
		if (g_file_get_contents (request->GetFilename (), &xap, &xap_len, NULL)) {
			if (xap_len == size && !memcmp (xap, content, size)) {
				// no change to the xap
				completed (false, NULL, user_data);
				CloseDownloader (false);
				g_free (content);
				g_free (xap);
				g_free (path);
				return;
			}
			g_free (xap);
		}
		g_free (content);
	}
	
	tmp = g_strdup_printf ("%s.tmp", path);
	
	if ((fp = fopen (tmp, "wb"))) {
		// write to the temporary file
		if (CopyFileTo (request->GetFilename (), fileno (fp)))
			err = ferror (fp);
		fclose (fp);
		
		if (err == 0) {
			// rename the temp file to the actual file
			if (g_rename (tmp, path) == -1)
				err = errno;
		}
	} else {
		err = errno;
	}
	
	g_free (path);
	g_free (tmp);
	
	if (err == 0) {
		// update the app's mtime
		// FIXME: get the Last-Modified: header from the downloader?
		app->mtime = time (NULL);
		db->SyncAppRecord (app);
	}
	
	completed (err == 0, err ? g_strerror (err) : NULL, user_data);
	
	CloseDownloader (false);
}
Example #2
0
//---------------------------------------------------------------------------
void __fastcall TDialogProjectNew::ButtonCreateClick(TObject *Sender)
{
  TTreeNode *TreeNodeLog = FormMain->Log(0, "Create new project '" + Edit->Text + "'");
  FormMain->Log(TreeNodeLog, CreateDir(Edit->Text) ? 1 : 3, "Create directory '" + Edit->Text + "'");
  for (int I = 1; I < TreeView->Items->Count; I++) {
    TTreeNode *TreeNode = TreeView->Items->Item[I];
    bool IsDirectory = TreeNode->ImageIndex == 2;
    String SourcePath = TreeNode->Text;
    while (TreeNode->Level >= 2) {
      TreeNode = TreeNode->Parent;
      SourcePath = TreeNode->Text + "\\" + SourcePath;
    }
    String TargetPath = Edit->Text + "\\" + SourcePath;
    SourcePath = TreeView->Items->Item[0]->Text + "\\" + SourcePath;
    if (IsDirectory) {
      bool Success = CreateDir(TargetPath);
      FormMain->Log(TreeNodeLog, Success ? 1 : 3, "Create directory '" + TargetPath + "'");
    } else {
      bool Success = CopyFileTo(SourcePath, TargetPath);
      FormMain->Log(TreeNodeLog, Success ? 1 : 3, "Copy file '" + SourcePath + "' --> '" + TargetPath + "'");
    }
  }
  ModalResult = mrOk;
}
Example #3
0
void TFrmMain::SaveToFile(const char* pszFileName)
{
    char szFileName[255];
    FILE* stream;




    fnsplit(pszFileName, 0, 0, szFileName, 0);
    strcat(szFileName, "_new.dbc");


    AnsiString NewFileName = ExtractFilePath(Application->ExeName) + szFileName; //=pszFileName;
    int iFileHandle; //文件句柄
    AnsiString  iniSetFile = ExtractFilePath(Application->ExeName) + "BcdEditer.ini";
    AnsiString SectionName = ExtractFileName(CurrentOpenFile);

    DWORD w;

    CopyFileTo(pszFileName, NewFileName);

    iFileHandle = FileOpen(NewFileName, fmOpenRead | fmOpenWrite); //打开文件

    if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
            == NULL)
    {
        ShowMessage("打开文件出错");
        return;
    }


    int iVal;
    float fVal;
    bool isFloat;
    int ColType;

    FileSeek(iFileHandle, 0x14, 0);
    TIniFile* ini;
    ini = new TIniFile(iniSetFile);

    for (int i = 1; i < sgEdit->RowCount; i++)
    {
        for (int j = 1; j < sgEdit->ColCount; j++)
        {
            if (j == 1) //ID
            {
                iVal = StrToInt(sgEdit->Cells[j][i]);
                FileWrite(iFileHandle, &iVal, 4);
            }
            else
            {

                //ColType= ini->ReadInteger(SectionName,"ColType"+IntToStr(j-1),0);
                //thOpen->ColType[10000];

                switch (thOpen->ColType[j])
                {
                    case 0: //整型
                        iVal = StrToFloat(sgEdit->Cells[j][i]);
                        FileWrite(iFileHandle, &iVal, 4);
                        break;
                    case 1: //浮点
                        fVal = StrToFloat(sgEdit->Cells[j][i]);
                        FileWrite(iFileHandle, &fVal, 4);
                        break;
                    case 2: //文本
                        fseek(stream, 0x14 + (i * (sgEdit->ColCount - 1) + (j - 1)) * 4, 0);
                        fread(&iVal, 4, 1, stream);
                        FileWrite(iFileHandle, &iVal, 4);
                        break;
                    default: //整型
                        iVal = StrToFloat(sgEdit->Cells[j][i]);
                        FileWrite(iFileHandle, &iVal, 4);
                }
            }
        }
    }
    FileClose(iFileHandle);
    fclose(stream);

    delete ini;
    ShowMessage("Save To File:" + NewFileName);
}