當前位置: 首頁>>代碼示例>>Golang>>正文


Golang AppDescriptor.GetDescription方法代碼示例

本文整理匯總了Golang中github.com/giancosta86/moondeploy/v3/descriptors.AppDescriptor.GetDescription方法的典型用法代碼示例。如果您正苦於以下問題:Golang AppDescriptor.GetDescription方法的具體用法?Golang AppDescriptor.GetDescription怎麽用?Golang AppDescriptor.GetDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/giancosta86/moondeploy/v3/descriptors.AppDescriptor的用法示例。


在下文中一共展示了AppDescriptor.GetDescription方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CreateDesktopShortcut

func (app *App) CreateDesktopShortcut(launcher launchers.Launcher, referenceDescriptor descriptors.AppDescriptor) (err error) {
	desktopDir, err := caravel.GetUserDesktop()
	if err != nil {
		return err
	}

	if !caravel.DirectoryExists(desktopDir) {
		return fmt.Errorf("Expected desktop dir '%v' not found", desktopDir)
	}

	shortcutFileName := caravel.FormatFileName(referenceDescriptor.GetName()) + ".desktop"
	log.Debug("Shortcut file name: '%v'", shortcutFileName)

	shortcutFilePath := filepath.Join(desktopDir, shortcutFileName)

	log.Info("Creating desktop shortcut: '%v'...", shortcutFilePath)

	shortcutFile, err := os.OpenFile(shortcutFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0700)
	if err != nil {
		return err
	}
	defer func() {
		shortcutFile.Close()
		if err != nil {
			os.Remove(shortcutFilePath)
		}
	}()

	actualIconPath := app.GetActualIconPath(launcher)

	shortcutContent := fmt.Sprintf(linuxShortcutContent,
		referenceDescriptor.GetName(),
		referenceDescriptor.GetDescription(),
		launcher.GetExecutable(),
		app.GetLocalDescriptorPath(),
		actualIconPath)

	_, err = shortcutFile.Write([]byte(shortcutContent))
	if err != nil {
		return err
	}

	log.Notice("Desktop shortcut created")

	return nil
}
開發者ID:giancosta86,項目名稱:moondeploy,代碼行數:46,代碼來源:desktop_linux.go

示例2: CreateDesktopShortcut

func (app *App) CreateDesktopShortcut(launcher launchers.Launcher, referenceDescriptor descriptors.AppDescriptor) (err error) {
	desktopDir, err := caravel.GetUserDesktop()
	if err != nil {
		return err
	}

	shortcutName := caravel.FormatFileName(referenceDescriptor.GetName()) + ".lnk"
	log.Debug("Shortcut file name: '%v'", shortcutName)

	shortcutFilePath := filepath.Join(desktopDir, shortcutName)
	log.Debug("Shortcut path: '%v'", shortcutFilePath)

	log.Info("Creating desktop shortcut: '%v'...", shortcutFilePath)

	log.Debug("Creating temp file for script...")

	salt := rand.Int63()
	tempFileName := fmt.Sprintf("shortcutScript_%v_%v.vbs", time.Now().Unix(), salt)
	tempFilePath := filepath.Join(os.TempDir(), tempFileName)
	tempFile, err := os.Create(tempFilePath)

	if err != nil {
		return err
	}
	defer func() {
		tempFile.Close()

		tempRemovalErr := os.Remove(tempFilePath)
		if tempRemovalErr != nil {
			log.Warning("Cannot remove the temp script: %v", tempFilePath)
		} else {
			log.Debug("Temp script successfully removed")
		}

		if err != nil {
			os.Remove(shortcutFilePath)
		}
	}()

	log.Debug("Temp script file created: %v", tempFilePath)
	actualIconPath := app.GetActualIconPath(launcher)
	log.Debug("Actual icon path: '%v'", actualIconPath)

	workingDirectory := filepath.Dir(app.GetLocalDescriptorPath())
	log.Debug("Working directory: '%v'", workingDirectory)

	shortcutScript := fmt.Sprintf(windowsShortcutContent,
		shortcutFilePath,
		app.GetLocalDescriptorPath(),
		referenceDescriptor.GetDescription(),
		actualIconPath,
		workingDirectory)

	log.Debug("Writing script temp file...")
	tempFile.Write([]byte(shortcutScript))
	tempFile.Close()
	log.Debug("Temp script ready")

	log.Debug("Now executing the temp script...")

	shortcutCreationCommand := exec.Command("wscript", "/b", "/nologo", tempFilePath)

	err = shortcutCreationCommand.Run()
	if err != nil {
		return err
	}

	if !shortcutCreationCommand.ProcessState.Success() {
		return fmt.Errorf("The script did not run successfully")
	}

	log.Debug("The script was successful")

	return nil
}
開發者ID:giancosta86,項目名稱:moondeploy,代碼行數:75,代碼來源:desktop_windows.go


注:本文中的github.com/giancosta86/moondeploy/v3/descriptors.AppDescriptor.GetDescription方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。